//https://philippegroarke.com/posts/2018/easy_defensive_programming/
//http://www.modernescpp.com/index.php/c-core-guidelines-regular-and-semiregular-typs
template <class T>
constexpr bool fulfills_rule_of_5() {
static_assert(std::is_destructible_v<T>, "T : must be destructible");
static_assert(std::is_copy_constructible_v<T>, "T : must be copy constructible");
static_assert(std::is_move_constructible_v<T>, "T : must be move constructible");
static_assert(std::is_copy_assignable_v<T>, "T : must be copy assignable");
static_assert(std::is_move_assignable_v<T>, "T : must be move assignable");
return std::is_destructible_v<T> && std::is_copy_constructible_v<T>
&& std::is_move_constructible_v<T> && std::is_copy_assignable_v<T>
&& std::is_move_assignable_v<T>;
}
struct the_mighty_potato {
the_mighty_potato(int some_number, int mul) : carbs(some_number * mul) {}
int carbs{ 42 };
std::unique_ptr<int> calories{ nullptr };
};
static_assert(fulfills_rule_of_5<the_mighty_potato>(), "the_might_potato: must fulfill rule of 5"); // Fails
Comments
0 B
|0 👍
/0 👎
0 B
|0 👍
/0 👎