Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <utility>
- #include <type_traits>
- #include <iostream>
- template<typename UnnamedType>
- struct container {
- private:
- template<typename... Params>
- constexpr auto test_validity(int) -> decltype(new UnnamedType((std::declval<Params>())...),
- std::true_type()) {
- return std::true_type();
- }
- template<typename... Params>
- constexpr std::false_type test_validity(...) {
- return std::false_type();
- }
- public:
- template<typename... Params>
- constexpr auto operator()(Params &&...) {
- return test_validity<Params...>(int());
- }
- };
- template<typename UnnamedType>
- constexpr auto is_valid() {
- return container<UnnamedType>();
- }
- class A {
- public:
- A() {
- std::cout << "DC" << std::endl;
- }
- A(int i, float f) {
- std::cout << "IF: " << i << " " << f << std::endl;
- }
- };
- template <class Type>
- class SMM{
- public:
- template <class ...Args>
- explicit SMM(Args... args ){
- static_assert(is_valid<Type>()(args...),
- "The Memory that you try to manage have not the right definition of allocate method.");
- Type(args...);
- }
- };
- int main() {
- SMM<A>
- smmDefault,
- smmFail(1),
- smm(1, 1.2);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement