Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,76 @@ | ||
// Copyright (c) 2002 Peter Dimov and Multi Media Ltd. | ||
// Copyright (c) 2009 Steven Watanabe | ||
// Copyright (c) 2011-2013 Hartmut Kaiser | ||
// Copyright (c) 2013 Agustin Berge | ||
// Copyright (c) 2013-2016 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) | ||
|
||
#if !defined(HPX_UTIL_PROTECT_SEP_23_2011_1230PM) | ||
#define HPX_UTIL_PROTECT_SEP_23_2011_1230PM | ||
#ifndef HPX_UTIL_PROTECT_HPP | ||
#define HPX_UTIL_PROTECT_HPP | ||
|
||
#include <hpx/config.hpp> | ||
#include <hpx/traits/is_bind_expression.hpp> | ||
#include <hpx/util/decay.hpp> | ||
|
||
#include <type_traits> | ||
#include <utility> | ||
|
||
namespace hpx { namespace util { namespace detail | ||
namespace hpx { namespace util | ||
{ | ||
/////////////////////////////////////////////////////////////////////////// | ||
template <typename F> | ||
class protected_bind : public F | ||
namespace detail | ||
{ | ||
public: | ||
// copy constructor | ||
protected_bind(protected_bind const& other) | ||
: F(other) | ||
{} | ||
|
||
// move constructor | ||
protected_bind(protected_bind && other) | ||
: F(std::move(other)) | ||
{} | ||
template <typename F> | ||
class protected_bind : public F | ||
{ | ||
public: | ||
explicit protected_bind(F const& f) | ||
: F(f) | ||
{} | ||
|
||
explicit protected_bind(F const & f) | ||
: F(f) | ||
{} | ||
explicit protected_bind(F&& f) | ||
: F(std::move(f)) | ||
{} | ||
|
||
explicit protected_bind(F && f) | ||
: F(std::move(f)) | ||
{} | ||
#if defined(HPX_HAVE_CXX11_DEFAULTED_FUNCTIONS) | ||
protected_bind(protected_bind const&) = default; | ||
protected_bind(protected_bind&&) = default; | ||
#else | ||
protected_bind(protected_bind const& other) | ||
: F(other) | ||
{} | ||
|
||
protected_bind& operator=(protected_bind const & rhs) | ||
{ | ||
F::operator=(rhs); | ||
return *this; | ||
} | ||
protected_bind(protected_bind&& other) | ||
: F(std::move(other)) | ||
{} | ||
#endif | ||
|
||
protected_bind& operator=(protected_bind && rhs) | ||
{ | ||
F::operator=(std::move(rhs)); | ||
return *this; | ||
} | ||
}; | ||
}}} // namespace hpx::util::detail | ||
HPX_DELETE_COPY_ASSIGN(protected_bind); | ||
HPX_DELETE_MOVE_ASSIGN(protected_bind); | ||
}; | ||
} | ||
|
||
namespace hpx { namespace util | ||
{ | ||
/////////////////////////////////////////////////////////////////////////// | ||
template <typename T> | ||
typename std::enable_if< | ||
traits::is_bind_expression<typename util::decay<T>::type>::value | ||
, detail::protected_bind<typename util::decay<T>::type> | ||
>::type | ||
protect(T && f) | ||
traits::is_bind_expression<typename std::decay<T>::type>::value | ||
, detail::protected_bind<typename std::decay<T>::type> | ||
>::type protect(T&& f) | ||
{ | ||
return detail::protected_bind< | ||
typename util::decay<T>::type | ||
typename std::decay<T>::type | ||
>(std::forward<T>(f)); | ||
} | ||
|
||
// leave everything that is not a bind expression as is | ||
template <typename T> | ||
typename std::enable_if< | ||
!traits::is_bind_expression<typename util::decay<T>::type>::value | ||
!traits::is_bind_expression<typename std::decay<T>::type>::value | ||
, T | ||
>::type | ||
protect(T && v) //-V659 | ||
>::type protect(T&& v) //-V659 | ||
{ | ||
return std::forward<T>(v); | ||
} | ||
}} // namespace hpx::util | ||
}} | ||
|
||
#endif | ||
#endif /*HPX_UTIL_PROTECT_HPP*/ |