Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. [Solved]Is this implement safe(awkward variant)
Forum Updated to NodeBB v4.3 + New Features

[Solved]Is this implement safe(awkward variant)

Scheduled Pinned Locked Moved C++ Gurus
1 Posts 1 Posters 924 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    stereomatching
    wrote on last edited by
    #1

    @
    #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).

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved