Skip to content

Commit

Permalink
Circumvent scary warning about placement new creating object of large…
Browse files Browse the repository at this point in the history
…r size than space is available
  • Loading branch information
hkaiser committed Jul 31, 2017
1 parent d14037a commit c55df05
Showing 1 changed file with 34 additions and 20 deletions.
54 changes: 34 additions & 20 deletions hpx/util/any.hpp
Expand Up @@ -450,11 +450,7 @@ namespace hpx { namespace util
object(nullptr)
{
typedef typename util::decay<T>::type value_type;

if (detail::any::get_table<value_type>::is_small::value)
new (&object) value_type(x);
else
object = new value_type(x);
new_object(object, x, detail::any::get_table<value_type>::is_small());
}

// Move constructor
Expand All @@ -481,11 +477,8 @@ namespace hpx { namespace util
object(nullptr)
{
typedef typename util::decay<T>::type value_type;

if (detail::any::get_table<value_type>::is_small::value)
new (&object) value_type(std::forward<T>(x));
else
object = new value_type(std::forward<T>(x));
new_object(object, std::forward<T>(x),
detail::any::get_table<value_type>::is_small());
}

~basic_any()
Expand All @@ -512,6 +505,20 @@ namespace hpx { namespace util
return *this;
}

template <typename T>
static void new_object(void*& object, T && x, std::true_type)
{
typedef typename util::decay<T>::type value_type;
new (&object) value_type(std::forward<T>(x));
}

template <typename T>
static void new_object(void*& object, T && x, std::false_type)
{
typedef typename util::decay<T>::type value_type;
object = new value_type(std::forward<T>(x));
}

public:
// copy assignment operator
basic_any& operator=(basic_any const& x)
Expand Down Expand Up @@ -733,11 +740,7 @@ namespace hpx { namespace util
object(nullptr)
{
typedef typename util::decay<T>::type value_type;

if (detail::any::get_table<value_type>::is_small::value)
new (&object) value_type(x);
else
object = new value_type(x);
new_object(object, x, detail::any::get_table<value_type>::is_small());
}

// Move constructor
Expand All @@ -764,11 +767,8 @@ namespace hpx { namespace util
object(nullptr)
{
typedef typename util::decay<T>::type value_type;

if (detail::any::get_table<value_type>::is_small::value)
new (&object) value_type(std::forward<T>(x));
else
object = new value_type(std::forward<T>(x));
new_object(object, std::forward<T>(x),
detail::any::get_table<value_type>::is_small());
}

~basic_any()
Expand All @@ -794,6 +794,20 @@ namespace hpx { namespace util
return *this;
}

template <typename T>
static void new_object(void*& object, T && x, std::true_type)
{
typedef typename util::decay<T>::type value_type;
new (&object) value_type(std::forward<T>(x));
}

template <typename T>
static void new_object(void*& object, T && x, std::false_type)
{
typedef typename util::decay<T>::type value_type;
object = new value_type(std::forward<T>(x));
}

public:
// copy assignment operator
basic_any& operator=(basic_any const& x)
Expand Down

0 comments on commit c55df05

Please sign in to comment.