1 #ifndef BOOST_SERIALIZATION_STRONG_TYPEDEF_HPP 2 #define BOOST_SERIALIZATION_STRONG_TYPEDEF_HPP 3 4 // MS compatible compilers support #pragma once 5 #if defined(_MSC_VER) 6 # pragma once 7 #endif 8 9 /////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8 10 // strong_typedef.hpp: 11 12 // (C) Copyright 2002 Robert Ramey - http://www.rrsd.com . 13 // (C) Copyright 2016 Ashish Sadanandan 14 // Use, modification and distribution is subject to the Boost Software 15 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at 16 // http://www.boost.org/LICENSE_1_0.txt) 17 18 // See http://www.boost.org/libs/serialization for updates, documentation, and revision history. 19 20 // macro used to implement a strong typedef. strong typedef 21 // guarentees that two types are distinguised even though the 22 // share the same underlying implementation. typedef does not create 23 // a new type. BOOST_STRONG_TYPEDEF(T, D) creates a new type named D 24 // that operates as a type T. 25 26 #include <boost/config.hpp> 27 #include <boost/operators.hpp> 28 #include <boost/type_traits/has_nothrow_assign.hpp> 29 #include <boost/type_traits/has_nothrow_constructor.hpp> 30 #include <boost/type_traits/has_nothrow_copy.hpp> 31 32 #define BOOST_STRONG_TYPEDEF(T, D) \ 33 struct D \ 34 : boost::totally_ordered1< D \ 35 , boost::totally_ordered2< D, T \ 36 > > \ 37 { \ 38 T t; \ 39 explicit D(const T& t_) BOOST_NOEXCEPT_IF(boost::has_nothrow_copy_constructor<T>::value) : t(t_) {} \ 40 D() BOOST_NOEXCEPT_IF(boost::has_nothrow_default_constructor<T>::value) : t() {} \ 41 D(const D & t_) BOOST_NOEXCEPT_IF(boost::has_nothrow_copy_constructor<T>::value) : t(t_.t) {} \ 42 D& operator=(const D& rhs) BOOST_NOEXCEPT_IF(boost::has_nothrow_assign<T>::value) {t = rhs.t; return *this;} \ 43 D& operator=(const T& rhs) BOOST_NOEXCEPT_IF(boost::has_nothrow_assign<T>::value) {t = rhs; return *this;} \ 44 operator const T&() const {return t;} \ 45 operator T&() {return t;} \ 46 bool operator==(const D& rhs) const {return t == rhs.t;} \ 47 bool operator<(const D& rhs) const {return t < rhs.t;} \ 48 }; 49 50 #endif // BOOST_SERIALIZATION_STRONG_TYPEDEF_HPP 51