mirror of
https://github.com/boostorg/utility.git
synced 2025-05-09 15:04:00 +00:00
added is_reference_wrapper<>, unwrap_reference<>
[SVN r12470]
This commit is contained in:
parent
c7c09696db
commit
f3f697bbc8
@ -1,9 +1,9 @@
|
|||||||
#ifndef BOOST_REF_HPP_INCLUDED
|
#ifndef BOOST_REF_HPP_INCLUDED
|
||||||
#define BOOST_REF_HPP_INCLUDED
|
# define BOOST_REF_HPP_INCLUDED
|
||||||
|
|
||||||
#if _MSC_VER+0 >= 1020
|
# if _MSC_VER+0 >= 1020
|
||||||
#pragma once
|
# pragma once
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// ref.hpp - ref/cref, useful helper functions
|
// ref.hpp - ref/cref, useful helper functions
|
||||||
@ -25,6 +25,7 @@ namespace boost
|
|||||||
template<class T> class reference_wrapper
|
template<class T> class reference_wrapper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
typedef T type;
|
||||||
|
|
||||||
explicit reference_wrapper(T & t): t_(t) {}
|
explicit reference_wrapper(T & t): t_(t) {}
|
||||||
|
|
||||||
@ -39,11 +40,11 @@ private:
|
|||||||
reference_wrapper & operator= (reference_wrapper const &);
|
reference_wrapper & operator= (reference_wrapper const &);
|
||||||
};
|
};
|
||||||
|
|
||||||
#if defined(__BORLANDC__) && (__BORLANDC__ <= 0x551)
|
# if defined(__BORLANDC__) && (__BORLANDC__ <= 0x551)
|
||||||
#define BOOST_REF_CONST
|
# define BOOST_REF_CONST
|
||||||
#else
|
# else
|
||||||
#define BOOST_REF_CONST const
|
# define BOOST_REF_CONST const
|
||||||
#endif
|
# endif
|
||||||
|
|
||||||
template<class T> inline reference_wrapper<T> BOOST_REF_CONST ref(T & t)
|
template<class T> inline reference_wrapper<T> BOOST_REF_CONST ref(T & t)
|
||||||
{
|
{
|
||||||
@ -55,7 +56,87 @@ template<class T> inline reference_wrapper<T const> BOOST_REF_CONST cref(T const
|
|||||||
return reference_wrapper<T const>(t);
|
return reference_wrapper<T const>(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef BOOST_REF_CONST
|
# undef BOOST_REF_CONST
|
||||||
|
|
||||||
|
# ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
|
template<typename T>
|
||||||
|
class is_reference_wrapper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BOOST_STATIC_CONSTANT(bool, value = false);
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class is_reference_wrapper<reference_wrapper<T> >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class unwrap_reference
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef T type;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class unwrap_reference<reference_wrapper<T> >
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef T type;
|
||||||
|
};
|
||||||
|
# else // no partial specialization
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
typedef char (&yes_reference_wrapper_t)[1];
|
||||||
|
typedef char (&no_reference_wrapper_t)[2];
|
||||||
|
|
||||||
|
no_reference_wrapper_t is_reference_wrapper_test(...);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
yes_reference_wrapper_t is_reference_wrapper_test(reference_wrapper<T>*);
|
||||||
|
|
||||||
|
template<bool wrapped>
|
||||||
|
struct reference_unwrapper
|
||||||
|
{
|
||||||
|
template <class T>
|
||||||
|
struct apply
|
||||||
|
{
|
||||||
|
typedef T type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct reference_unwrapper<true>
|
||||||
|
{
|
||||||
|
template <class T>
|
||||||
|
struct apply
|
||||||
|
{
|
||||||
|
typedef typename T::type type;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
class is_reference_wrapper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static T* t;
|
||||||
|
BOOST_STATIC_CONSTANT(
|
||||||
|
bool, value = (
|
||||||
|
sizeof(detail::is_reference_wrapper_test(t))
|
||||||
|
== sizeof(detail::yes_reference_wrapper_t)));
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class unwrap_reference
|
||||||
|
: public detail::reference_unwrapper<
|
||||||
|
is_reference_wrapper<T>::value
|
||||||
|
>::template apply<T>
|
||||||
|
{};
|
||||||
|
|
||||||
|
# endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user