Skip to content

Commit

Permalink
Merge pull request #1770 from STEllAR-GROUP/decay
Browse files Browse the repository at this point in the history
Forwarding decay to std::
  • Loading branch information
sithhell committed Sep 29, 2015
2 parents 9efbc87 + 693bf34 commit 5d3897b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 28 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Expand Up @@ -771,6 +771,9 @@ hpx_check_for_cxx11_std_is_null_pointer(
hpx_check_for_cxx11_std_is_placeholder(
DEFINITIONS HPX_HAVE_CXX11_STD_IS_PLACEHOLDER)

hpx_check_for_cxx11_std_reference_wrapper(
DEFINITIONS HPX_HAVE_CXX11_STD_REFERENCE_WRAPPER)

hpx_check_for_cxx11_std_unique_ptr(
REQUIRED "HPX needs support for C++11 std::unique_ptr")

Expand Down
7 changes: 7 additions & 0 deletions cmake/HPX_AddConfigTest.cmake
Expand Up @@ -288,6 +288,13 @@ macro(hpx_check_for_cxx11_std_is_placeholder)
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_reference_wrapper)
add_hpx_config_test(HPX_WITH_CXX11_REFERENCE_WRAPPER
SOURCE cmake/tests/cxx11_std_reference_wrapper.cpp
FILE ${ARGN})
endmacro()

###############################################################################
macro(hpx_check_for_cxx11_std_initializer_list)
add_hpx_config_test(HPX_WITH_CXX11_STD_INITIALIZER_LIST
Expand Down
14 changes: 14 additions & 0 deletions cmake/tests/cxx11_std_reference_wrapper.cpp
@@ -0,0 +1,14 @@
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2015 Agustin Berge
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
////////////////////////////////////////////////////////////////////////////////

#include <functional>

int main()
{
int lvalue = 0;
std::reference_wrapper<int> wrapper = std::ref(lvalue);
}
48 changes: 20 additions & 28 deletions hpx/util/decay.hpp
@@ -1,42 +1,26 @@
// Copyright (c) 2012 Thomas Heller
// Copyright (c) 2013 Agustin Berge
// Copyright (c) 2013-2015 Agustin Berge
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#ifndef HPX_UTIL_DECAY_HPP
#define HPX_UTIL_DECAY_HPP

#include <boost/mpl/eval_if.hpp>
#include <boost/mpl/identity.hpp>
#include <hpx/config.hpp>

#include <boost/ref.hpp>
#include <boost/type_traits/config.hpp>
#include <boost/type_traits/is_array.hpp>
#include <boost/type_traits/is_function.hpp>
#include <boost/type_traits/remove_bounds.hpp>
#include <boost/type_traits/add_pointer.hpp>
#include <boost/type_traits/remove_cv.hpp>
#include <boost/type_traits/remove_reference.hpp>

#if defined(HPX_HAVE_CXX11_STD_REFERENCE_WRAPPER)
#include <functional>
#endif
#include <utility>

namespace hpx { namespace util
{
template <typename T>
struct decay
{
typedef typename boost::remove_reference<T>::type Ty;

typedef
typename boost::mpl::eval_if<
boost::is_array<Ty>
, boost::mpl::identity<typename boost::remove_bounds<Ty>::type *>
, typename boost::mpl::eval_if<
boost::is_function<Ty>
, boost::add_pointer<Ty>
, boost::remove_cv<Ty>
>
>::type
type;
};
struct decay : std::decay<T>
{};

namespace detail
{
Expand All @@ -47,15 +31,23 @@ namespace hpx { namespace util
};

template <typename X>
struct decay_unwrap_impl<boost::reference_wrapper<X> >
struct decay_unwrap_impl< ::boost::reference_wrapper<X> >
{
typedef X& type;
};

#if defined(HPX_HAVE_CXX11_STD_REFERENCE_WRAPPER)
template <typename X>
struct decay_unwrap_impl< ::std::reference_wrapper<X> >
{
typedef X& type;
};
#endif
}

template <typename T>
struct decay_unwrap
: detail::decay_unwrap_impl<typename decay<T>::type>
: detail::decay_unwrap_impl<typename std::decay<T>::type>
{};
}}

Expand Down

0 comments on commit 5d3897b

Please sign in to comment.