[Solved]Is this implement safe(awkward variant)



  • @
    #include <iostream>
    #include <new>
    #include <type_traits>

    template<typename T, typename U>
    struct promote
    {
      typedef typename std::conditional<(sizeof(T) > sizeof(U)), T, U>::type type;
    };    
    
    template<class U, class V>
    class risk_implementation
    {
      public:
    
      template<class T>
      risk_implementation(T const &t)    
      {
        new(storage_) T(t);
      }      
    
     //easier to do some test with public
     typedef typename promote<U, V>::type Bigger;
     typedef typename std::aligned_storage<sizeof(Bigger), alignof(Bigger)>::type storage_type;
     storage_type storage_[1];           
    };
    

    @

    I find out that this may cause problems of alignment(depend of the types).


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.