diff --git a/module-1/homework/TypeTraits/type_traits/is_copy_constructible.h b/module-1/homework/TypeTraits/type_traits/is_copy_constructible.h index b02d9f02..8634d2c9 100644 --- a/module-1/homework/TypeTraits/type_traits/is_copy_constructible.h +++ b/module-1/homework/TypeTraits/type_traits/is_copy_constructible.h @@ -10,29 +10,69 @@ struct LibCppIsConstructible; template struct IsInvalidBaseToDerivedCast { - // Your code goes here + using derived = uncvref_t; + using base = uncvref_t; + using value = + std::integral_constant && + std::is_base_of_v && + !LibCppIsConstructible::type::value>; }; template -struct IsInvalidLvalueToRvalueCast : std::false_type { - // Your code goes here -}; +struct IsInvalidLvalueToRvalueCast : std::false_type {}; template struct IsInvalidLvalueToRvalueCast { - // Your code goes here + using to = uncvref_t; + using from = uncvref_t; + using value = + std::integral_constant && std::is_base_of_v>; }; struct IsConstructibleHelper { - // Your code goes here + template + static void ImplicitCast(To); + + template (Declval()))> + static std::true_type Castable(int); + + template (Declval()))> + static std::integral_constant::value && + !IsInvalidLvalueToRvalueCast::value> + Castable(double); + + template + static std::false_type Castable(...); + + template ()...))> + static std::true_type Constructible(int); + + template + static std::false_type Constructible(...); +}; + +template +struct LibCppIsConstructible { + using type = decltype(IsConstructibleHelper::Constructible(0)); +}; + +template +struct LibCppIsConstructible { + using type = decltype(IsConstructibleHelper::Constructible(0)); }; -// LibCppIsConstructible - partial specializations -// Your code goes here -// LibCppIsConstructible - partial specializations +template +struct LibCppIsConstructible { + using type = decltype(IsConstructibleHelper::Castable(0)); +}; + +template +struct LibCppIsConstructible { + using type = decltype(IsConstructibleHelper::Castable(0)); +}; template -struct IsConstructible : // Your code goes here {...} +struct IsConstructible : LibCppIsConstructible::type {}; template -struct IsCopyConstructible : // Your code goes here {...} \ No newline at end of file +struct IsCopyConstructible : LibCppIsConstructible::type {}; \ No newline at end of file diff --git a/module-1/homework/TypeTraits/type_traits/is_nothrow_move_constructible.h b/module-1/homework/TypeTraits/type_traits/is_nothrow_move_constructible.h index bd749521..0e744752 100644 --- a/module-1/homework/TypeTraits/type_traits/is_nothrow_move_constructible.h +++ b/module-1/homework/TypeTraits/type_traits/is_nothrow_move_constructible.h @@ -9,15 +9,31 @@ template struct LibCppIsNoThrowConstructible; -// LibCppIsNoThrowConstructible - partial specializations -// Your code goes here -// LibCppIsNoThrowConstructible - partial specializations +template +struct LibCppIsNoThrowConstructible { + using type = std::integral_constant()...))>; +}; + +template +struct LibCppIsNoThrowConstructible { + using type = + std::integral_constant(Declval()))>; +}; + +template +struct LibCppIsNoThrowConstructible { + using type = std::false_type; +}; template -struct IsNoThrowConstructible : // Your code goes here {...} +struct IsNoThrowConstructible + : LibCppIsNoThrowConstructible::value, std::is_reference_v, T, + Args...>::type {}; -template -struct IsNoThrowConstructible : // Your code goes here {...} +template +struct IsNoThrowConstructible + : LibCppIsNoThrowConstructible::value, std::is_reference_v, T>::type {}; template -struct IsNoThrowMoveConstructible : // Your code goes here {...} \ No newline at end of file +struct IsNoThrowMoveConstructible : IsNoThrowConstructible {}; \ No newline at end of file diff --git a/module-1/homework/TypeTraits/type_traits/move_if_noexcept.h b/module-1/homework/TypeTraits/type_traits/move_if_noexcept.h index 4ce67cec..37ba8e82 100644 --- a/module-1/homework/TypeTraits/type_traits/move_if_noexcept.h +++ b/module-1/homework/TypeTraits/type_traits/move_if_noexcept.h @@ -8,13 +8,12 @@ #include "utility.h" template -struct Conditional { - // Your code goes here -}; +struct Conditional; -// Conditional - partial specialization -// Your code goes here -// Conditional - partial specialization +template +struct Conditional { + using type = F; +}; template struct Conditional { @@ -22,8 +21,11 @@ struct Conditional { }; template -using conditional_v = // Your code goes here +using conditional_v = typename Conditional::type; -// MoveIfNoExcept -// Your code goes here -// MoveIfNoExcept \ No newline at end of file +template +typename Conditional::value && IsCopyConstructible::value, + const T&, T&&>::type +MoveIfNoExcept(T& x) noexcept { + return std::move(x); +} \ No newline at end of file diff --git a/module-1/homework/TypeTraits/type_traits/utility.h b/module-1/homework/TypeTraits/type_traits/utility.h index 1f0dc419..41d9dc8c 100644 --- a/module-1/homework/TypeTraits/type_traits/utility.h +++ b/module-1/homework/TypeTraits/type_traits/utility.h @@ -3,30 +3,89 @@ #include #include +template +struct RemoveConst { + using type = T; +}; + +template +struct RemoveConst { + using type = T; +}; + +template +using remove_const_t = typename RemoveConst::type; + +template +struct RemoveVolatile { + using type = T; +}; + +template +struct RemoveVolatile { + using type = T; +}; + +template +using remove_volatile_t = typename RemoveVolatile::type; + +template +struct RemoveReference { + using type = T; +}; + +template +struct RemoveReference { + using type = T; +}; + +template +struct RemoveReference { + using type = T; +}; + +template +using remove_reference_t = typename RemoveReference::type; + +template +struct Uncv { + using type = remove_const_t>; +}; + +template +using uncv_t = typename Uncv::type; + template struct Uncvref { - // Your code goes here + using type = uncv_t>; }; template -using uncvref_t = // Your code goes here +using uncvref_t = typename Uncvref::type; template struct AddConst { - using type = // Your code goes here + using type = const T; }; template -using add_const_t = // Your code goes here +using add_const_t = typename AddConst::type; template -struct AddLvalueReference : // Your code goes here +struct AddLvalueReference { + using type = T&; +}; + +template +struct AddRvalueReference { + using type = T&&; +}; template -struct AddRvalueReference : // Your code goes here +using add_lvalue_reference_t = typename AddLvalueReference::type; template -using add_lvalue_reference_t = // Your code goes here +using add_rvalue_reference_t = typename AddRvalueReference::type; template -using add_rvalue_reference_t = // Your code goes here \ No newline at end of file +add_rvalue_reference_t Declval() noexcept; \ No newline at end of file