1
0
forked from boostorg/core
Files
boost_core/include/boost/ref.hpp

63 lines
1.3 KiB
C++
Raw Normal View History

2001-08-23 18:42:16 +00:00
#ifndef BOOST_REF_HPP_INCLUDED
#define BOOST_REF_HPP_INCLUDED
2001-11-10 19:18:58 +00:00
#if _MSC_VER+0 >= 1020
2001-08-23 18:42:16 +00:00
#pragma once
#endif
//
2001-08-23 19:05:21 +00:00
// ref.hpp - ref/cref, useful helper functions
2001-08-23 18:42:16 +00:00
//
2001-08-23 19:05:21 +00:00
// Copyright (C) 1999, 2000 Jaakko J<>rvi (jaakko.jarvi@cs.utu.fi)
2001-11-10 19:18:58 +00:00
// Copyright (C) 2001 Peter Dimov
2001-08-23 18:42:16 +00:00
//
2001-08-23 19:05:21 +00:00
// Permission to copy, use, modify, sell and distribute this software
// is granted provided this copyright notice appears in all copies.
// This software is provided "as is" without express or implied
// warranty, and with no claim as to its suitability for any purpose.
2001-08-23 18:42:16 +00:00
//
2001-08-23 19:05:21 +00:00
// See http://www.boost.org/libs/bind/ref.html for documentation.
2001-08-23 18:42:16 +00:00
//
namespace boost
{
template<class T> class reference_wrapper
{
public:
2001-08-23 19:05:21 +00:00
explicit reference_wrapper(T & t): t_(t) {}
2001-08-23 18:42:16 +00:00
2001-08-23 19:05:21 +00:00
operator T & () const { return t_; }
2001-08-23 18:42:16 +00:00
2001-08-23 19:05:21 +00:00
T & get() const { return t_; }
2001-08-23 18:42:16 +00:00
private:
2001-08-23 19:05:21 +00:00
T & t_;
2001-08-23 18:42:16 +00:00
2001-08-23 19:05:21 +00:00
reference_wrapper & operator= (reference_wrapper const &);
2001-08-23 18:42:16 +00:00
};
#if defined(__BORLANDC__) && (__BORLANDC__ <= 0x551)
#define BOOST_REF_CONST
#else
#define BOOST_REF_CONST const
#endif
template<class T> inline reference_wrapper<T> BOOST_REF_CONST ref(T & t)
2001-08-23 18:42:16 +00:00
{
2001-08-23 19:05:21 +00:00
return reference_wrapper<T>(t);
2001-08-23 18:42:16 +00:00
}
template<class T> inline reference_wrapper<T const> BOOST_REF_CONST cref(T const & t)
2001-08-23 18:42:16 +00:00
{
2001-08-23 19:05:21 +00:00
return reference_wrapper<T const>(t);
2001-08-23 18:42:16 +00:00
}
#undef BOOST_REF_CONST
2001-08-23 18:42:16 +00:00
} // namespace boost
#endif // #ifndef BOOST_REF_HPP_INCLUDED