275 lines
5.6 KiB
C++
275 lines
5.6 KiB
C++
/**
|
|
* @file include/ActivMiddleware/CxxYZ/functional.h
|
|
*
|
|
* @brief Header file for easing C++11 (or later) <functional> features across compilers.
|
|
*/
|
|
|
|
#if (!defined ACTIV_CXXYX_FUNCTIONAL_H)
|
|
#define ACTIV_CXXYX_FUNCTIONAL_H
|
|
|
|
#include "ActivMiddleware/ActivMiddleware.h"
|
|
#include "ActivMiddleware/CxxYZ/type_traits.h"
|
|
|
|
#include ACTIV_BOOST_INCLUDE(move/move.hpp)
|
|
#include ACTIV_BOOST_INCLUDE(core/ref.hpp)
|
|
|
|
// Make ref, cref and bind available in Activ::CxxYZ.
|
|
#if (defined ACTIV_BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
|
|
|
#include ACTIV_BOOST_INCLUDE(bind/bind.hpp)
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
//! CxxYZ namespace.
|
|
namespace CxxYZ
|
|
{
|
|
|
|
using Boost::ref;
|
|
using Boost::cref;
|
|
using Boost::reference_wrapper;
|
|
using Boost::is_reference_wrapper;
|
|
using Boost::is_bind_expression;
|
|
|
|
using Boost::bind;
|
|
|
|
using namespace Boost::placeholders;
|
|
|
|
} // namespace CxxYZ
|
|
|
|
} // namespace Activ
|
|
|
|
#else
|
|
|
|
#include <functional>
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
//! CxxYZ namespace.
|
|
namespace CxxYZ
|
|
{
|
|
|
|
using std::ref;
|
|
using std::cref;
|
|
using std::reference_wrapper;
|
|
using Boost::is_reference_wrapper;
|
|
using std::is_bind_expression;
|
|
|
|
using std::bind;
|
|
using std::placeholders::_1;
|
|
using std::placeholders::_2;
|
|
using std::placeholders::_3;
|
|
using std::placeholders::_4;
|
|
using std::placeholders::_5;
|
|
using std::placeholders::_6;
|
|
using std::placeholders::_7;
|
|
using std::placeholders::_8;
|
|
using std::placeholders::_9;
|
|
|
|
} // namespace CxxYZ
|
|
|
|
} // namespace Activ
|
|
|
|
namespace ACTIV_BOOST_NAMESPACE
|
|
{
|
|
|
|
// Add std::reference_wrapper support to is_reference_wrapper.
|
|
template<typename T>
|
|
class is_reference_wrapper<std::reference_wrapper<T>>
|
|
{
|
|
public:
|
|
static const bool value = true;
|
|
};
|
|
|
|
template<typename T>
|
|
class is_reference_wrapper<const std::reference_wrapper<T>>
|
|
{
|
|
public:
|
|
static const bool value = true;
|
|
};
|
|
|
|
template<typename T>
|
|
class is_reference_wrapper<volatile std::reference_wrapper<T>>
|
|
{
|
|
public:
|
|
static const bool value = true;
|
|
};
|
|
|
|
template<typename T>
|
|
class is_reference_wrapper<const volatile std::reference_wrapper<T>>
|
|
{
|
|
public:
|
|
static const bool value = true;
|
|
};
|
|
|
|
} // namespace ACTIV_BOOST_NAMESPACE
|
|
|
|
#endif
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
#if (defined ACTIV_BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
|
|
|
#include ACTIV_BOOST_INCLUDE(function.hpp)
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
//! CxxYZ namespace.
|
|
namespace CxxYZ
|
|
{
|
|
|
|
using Boost::function;
|
|
|
|
} // namespace CxxYZ
|
|
|
|
} // namespace Activ
|
|
|
|
#else
|
|
|
|
#include <functional>
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
//! CxxYZ namespace.
|
|
namespace CxxYZ
|
|
{
|
|
|
|
using std::function;
|
|
|
|
} // namespace CxxYZ
|
|
|
|
} // namespace Activ
|
|
|
|
#endif
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
// Make hash available in Activ::CxxYZ.
|
|
|
|
// Always include boost, as who in their right mind is not going to use Boost::hash_combine/range etc.
|
|
// for their specialized std::hash?
|
|
#include ACTIV_BOOST_INCLUDE(functional/hash.hpp)
|
|
|
|
#if (defined ACTIV_BOOST_NO_CXX11_HDR_FUNCTIONAL)
|
|
|
|
#define ACTIV_CXXYZ_HASH_NAMESPACE Boost
|
|
|
|
#else
|
|
|
|
#include <functional>
|
|
|
|
#define ACTIV_CXXYZ_HASH_NAMESPACE std
|
|
|
|
#endif
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
//! CxxYZ namespace.
|
|
namespace CxxYZ
|
|
{
|
|
|
|
using ACTIV_CXXYZ_HASH_NAMESPACE::hash;
|
|
|
|
} // namespace CxxYZ
|
|
|
|
} // namespace Activ
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
//! Class to wrap any type and provide a const conversion operator.
|
|
template<typename T>
|
|
class TypeWrapper
|
|
{
|
|
public:
|
|
//! Constructor.
|
|
TypeWrapper(const T &value) :
|
|
m_value(value)
|
|
{
|
|
}
|
|
|
|
//! Constructor.
|
|
explicit TypeWrapper(ACTIV_BOOST_RV_REF(T) value) :
|
|
m_value(value)
|
|
{
|
|
}
|
|
|
|
//! Copy constructor.
|
|
explicit TypeWrapper(const TypeWrapper<T> &value) :
|
|
m_value(value.m_value)
|
|
{
|
|
}
|
|
|
|
//! Move constructor.
|
|
explicit TypeWrapper(ACTIV_BOOST_RV_REF(TypeWrapper<T>) value) :
|
|
m_value(CxxYZ::move(value.m_value))
|
|
{
|
|
}
|
|
|
|
//! Copy assignment.
|
|
TypeWrapper &operator=(ACTIV_BOOST_RV_REF(TypeWrapper<T>) value)
|
|
{
|
|
m_value = value.m_value;
|
|
|
|
return *this;
|
|
}
|
|
|
|
//! Move assignment.
|
|
TypeWrapper &operator=(ACTIV_BOOST_COPY_ASSIGN_REF(TypeWrapper<T>) value)
|
|
{
|
|
m_value = CxxYZ::move(value.m_value);
|
|
|
|
return *this;
|
|
}
|
|
|
|
//! Const conversion operator.
|
|
operator const T &() const
|
|
{
|
|
return m_value;
|
|
}
|
|
|
|
ACTIV_BOOST_COPYABLE_AND_MOVABLE(TypeWrapper<T>)
|
|
|
|
private:
|
|
T m_value;
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Metafunction to return provided type if it is not a bind type.
|
|
template<typename T, typename ENABLE = void>
|
|
class BindWrapper
|
|
{
|
|
public:
|
|
typedef T type;
|
|
};
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Metafunction to return a wrapper of the provided type when it is a bind type. Can help with bind composition.
|
|
template<typename T>
|
|
class BindWrapper<T, typename CxxYZ::enable_if<CxxYZ::is_bind_expression<T>::value>::type>
|
|
{
|
|
public:
|
|
typedef TypeWrapper<T> type;
|
|
};
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_CXXYX_FUNCTIONAL_H)
|