Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1. #include <utility>
  2. #include <type_traits>
  3. #include <iostream>
  4.  
  5. template<typename UnnamedType>
  6. struct container {
  7.  private:
  8.   template<typename... Params>
  9.   constexpr auto test_validity(int) -> decltype(new UnnamedType((std::declval<Params>())...),
  10.       std::true_type()) {
  11.     return std::true_type();
  12.   }
  13.   template<typename... Params>
  14.   constexpr std::false_type test_validity(...) {
  15.     return std::false_type();
  16.   }
  17.  
  18.  public:
  19.  
  20.   template<typename... Params>
  21.   constexpr auto operator()(Params &&...) {
  22.     return test_validity<Params...>(int());
  23.   }
  24. };
  25.  
  26. template<typename UnnamedType>
  27. constexpr auto is_valid() {
  28.   return container<UnnamedType>();
  29. }
  30.  
  31. class A {
  32.  public:
  33.   A() {
  34.     std::cout  << "DC" << std::endl;
  35.   }
  36.  
  37.   A(int i, float f) {
  38.     std::cout  << "IF: " << i << " " << f << std::endl;
  39.   }
  40. };
  41.  
  42.  
  43. template <class Type>
  44. class SMM{
  45.  public:
  46.   template <class ...Args>
  47.   explicit SMM(Args...  args ){
  48.     static_assert(is_valid<Type>()(args...),
  49.                   "The Memory that you try to manage have not the right definition of allocate method.");
  50.     Type(args...);
  51.   }
  52. };
  53.  
  54.  
  55. int main() {
  56.   SMM<A>
  57.       smmDefault,
  58.       smmFail(1),
  59.       smm(1, 1.2);
  60.  
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement