Proper sfinae for vector & point constructors instead of static_assert
This commit is contained in:
parent
1bfbaaa840
commit
4914be8099
3 changed files with 19 additions and 8 deletions
|
|
@ -32,4 +32,19 @@ namespace psemek::geom::detail
|
|||
};
|
||||
};
|
||||
|
||||
template <typename T, typename ... Args>
|
||||
struct all_convertible_to;
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct all_convertible_to<T>
|
||||
: std::true_type
|
||||
{};
|
||||
|
||||
template <typename T, typename H, typename ... Args>
|
||||
struct all_convertible_to<T, H, Args...>
|
||||
: std::bool_constant<std::is_convertible_v<H, T>
|
||||
&& all_convertible_to<T, Args...>::value>
|
||||
{};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,12 +24,10 @@ namespace psemek::geom
|
|||
point & operator = (point &) = default;
|
||||
point & operator = (point &&) = default;
|
||||
|
||||
template <typename ... Args>
|
||||
template <typename ... Args, typename = std::enable_if_t<(sizeof...(Args) == N) && detail::all_convertible_to<T, Args...>::value>>
|
||||
point(Args && ... args)
|
||||
: coords{ static_cast<T>(std::forward<Args>(args))... }
|
||||
{
|
||||
static_assert(sizeof...(Args) == N);
|
||||
}
|
||||
{}
|
||||
|
||||
std::size_t dimension() const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -29,12 +29,10 @@ namespace psemek::geom
|
|||
vector & operator = (vector &) = default;
|
||||
vector & operator = (vector &&) = default;
|
||||
|
||||
template <typename ... Args>
|
||||
template <typename ... Args, typename = std::enable_if_t<(sizeof...(Args) == N) && detail::all_convertible_to<T, Args...>::value>>
|
||||
vector(Args && ... args)
|
||||
: coords{ static_cast<T>(std::forward<Args>(args))... }
|
||||
{
|
||||
static_assert(sizeof...(Args) == N);
|
||||
}
|
||||
{}
|
||||
|
||||
std::size_t dimension() const
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue