feat: constructors of cartesian_vector refactored
This commit is contained in:
1 parent
7e1baf65fa
commit
4b5d37e83e
2 files changed
+37
-9
No files matched your search
@@ -53,26 +53,30 @@ public:
|
||||
T _coordinates_[3];
|
||||
using value_type = T;
|
||||
|
||||
cartesian_vector() = default;
|
||||
cartesian_vector(const cartesian_vector&) = default;
|
||||
cartesian_vector(cartesian_vector&&) = default;
|
||||
cartesian_vector& operator=(const cartesian_vector&) = default;
|
||||
cartesian_vector& operator=(cartesian_vector&&) = default;
|
||||
|
||||
template<std::convertible_to<T> Arg1, std::convertible_to<T>... Args>
|
||||
constexpr cartesian_vector(Arg1&& arg1, Args&&... args) :
|
||||
_coordinates_(std::forward<Arg1>(arg1), std::forward<Args>(args)...)
|
||||
template<typename... Args>
|
||||
requires(... && std::constructible_from<T, Args>)
|
||||
constexpr explicit(!(... && std::convertible_to<Args, T>)) cartesian_vector(Args&&... args) :
|
||||
_coordinates_{static_cast<T>(std::forward<Args>(args))...}
|
||||
{
|
||||
}
|
||||
|
||||
template<std::convertible_to<T> U>
|
||||
constexpr cartesian_vector(const cartesian_vector<U>& other) : _coordinates_{other[0], other[1], other[2]}
|
||||
template<typename U>
|
||||
requires std::constructible_from<T, U>
|
||||
constexpr explicit(!std::convertible_to<U, T>) cartesian_vector(const cartesian_vector<U>& other) :
|
||||
_coordinates_{static_cast<T>(other[0]), static_cast<T>(other[1]), static_cast<T>(other[2])}
|
||||
{
|
||||
}
|
||||
|
||||
template<std::convertible_to<T> U>
|
||||
constexpr cartesian_vector(cartesian_vector<U>&& other) :
|
||||
_coordinates_{std::move(other[0]), std::move(other[1]), std::move(other[2])}
|
||||
template<typename U>
|
||||
requires std::constructible_from<T, U>
|
||||
constexpr explicit(!std::convertible_to<U, T>) cartesian_vector(cartesian_vector<U>&& other) :
|
||||
_coordinates_{static_cast<T>(std::move(other[0])), static_cast<T>(std::move(other[1])),
|
||||
static_cast<T>(std::move(other[2]))}
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user