|
||||
File indexing completed on 2025-01-18 09:30:42
0001 // boost/identifier.hpp ----------------------------------------------------// 0002 0003 // Copyright Beman Dawes 2006 0004 0005 // Distributed under the Boost Software License, Version 1.0. (See accompanying 0006 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 0007 0008 // See documentation at http://www.boost.org/libs/utility 0009 0010 #ifndef BOOST_IDENTIFIER_HPP 0011 #define BOOST_IDENTIFIER_HPP 0012 0013 #include <boost/utility/enable_if.hpp> 0014 #include <boost/type_traits/is_base_of.hpp> 0015 #include <iosfwd> 0016 0017 namespace boost 0018 { 0019 namespace detail 0020 { 0021 // class template identifier ---------------------------------------------// 0022 0023 // Always used as a base class so that different instantiations result in 0024 // different class types even if instantiated with the same value type T. 0025 0026 // Expected usage is that T is often an integer type, best passed by 0027 // value. There is no reason why T can't be a possibly larger class such as 0028 // std::string, best passed by const reference. 0029 0030 // This implementation uses pass by value, based on expected common uses. 0031 0032 template <typename T, typename D> 0033 class identifier 0034 { 0035 public: 0036 typedef T value_type; 0037 0038 const value_type value() const { return m_value; } 0039 void assign( value_type v ) { m_value = v; } 0040 0041 bool operator==( const D & rhs ) const { return m_value == rhs.m_value; } 0042 bool operator!=( const D & rhs ) const { return m_value != rhs.m_value; } 0043 bool operator< ( const D & rhs ) const { return m_value < rhs.m_value; } 0044 bool operator<=( const D & rhs ) const { return m_value <= rhs.m_value; } 0045 bool operator> ( const D & rhs ) const { return m_value > rhs.m_value; } 0046 bool operator>=( const D & rhs ) const { return m_value >= rhs.m_value; } 0047 0048 typedef void (*unspecified_bool_type)(D); // without the D, unspecified_bool_type 0049 static void unspecified_bool_true(D){} // conversion allows relational operators 0050 // between different identifier types 0051 0052 operator unspecified_bool_type() const { return m_value == value_type() ? 0 : unspecified_bool_true; } 0053 bool operator!() const { return m_value == value_type(); } 0054 0055 // constructors are protected so that class can only be used as a base class 0056 protected: 0057 identifier() {} 0058 explicit identifier( value_type v ) : m_value(v) {} 0059 0060 private: 0061 T m_value; 0062 }; 0063 0064 //#ifndef BOOST_NO_SFINAE 0065 0066 // template <class Ostream, class Id> 0067 // typename enable_if< is_base_of< identifier< typename Id::value_type, Id >, Id >, 0068 // Ostream & >::type operator<<( Ostream & os, const Id & id ) 0069 // { 0070 // return os << id.value(); 0071 // } 0072 0073 // template <class Istream, class Id> 0074 // typename enable_if< is_base_of< identifier< typename Id::value_type, Id >, Id >, 0075 // Istream & >::type operator>>( Istream & is, Id & id ) 0076 // { 0077 // typename Id::value_type v; 0078 // is >> v; 0079 // id.value( v ); 0080 // return is; 0081 // } 0082 //#endif 0083 0084 } // namespace detail 0085 } // namespace boost 0086 0087 #endif // BOOST_IDENTIFIER_HPP
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |