| 1 | /////////////////////////////////////////////////////////////////////////////// |
| 2 | /// \file is_noncopyable.hpp |
| 3 | /// Utility for detecting when types are non-copyable |
| 4 | // |
| 5 | // Copyright 2008 Eric Niebler. Distributed under the Boost |
| 6 | // Software License, Version 1.0. (See accompanying file |
| 7 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) |
| 8 | |
| 9 | #ifndef BOOST_PROTO_DETAIL_IS_NONCOPYABLE_HPP_EAN_19_07_2012 |
| 10 | #define BOOST_PROTO_DETAIL_IS_NONCOPYABLE_HPP_EAN_19_07_2012 |
| 11 | |
| 12 | #include <boost/noncopyable.hpp> |
| 13 | #include <boost/mpl/or.hpp> |
| 14 | #include <boost/mpl/bool.hpp> |
| 15 | #include <boost/type_traits/is_base_of.hpp> |
| 16 | #include <boost/type_traits/is_abstract.hpp> |
| 17 | #include <boost/type_traits/is_function.hpp> |
| 18 | #include <boost/proto/proto_fwd.hpp> |
| 19 | |
| 20 | namespace boost { namespace proto { namespace detail |
| 21 | { |
| 22 | // All classes derived from std::ios_base have these public nested types, |
| 23 | // and are non-copyable. This is an imperfect test, but it's the best we |
| 24 | // we can do. |
| 25 | template<typename T> |
| 26 | yes_type check_is_iostream( |
| 27 | typename T::failure * |
| 28 | , typename T::Init * |
| 29 | , typename T::fmtflags * |
| 30 | , typename T::iostate * |
| 31 | , typename T::openmode * |
| 32 | , typename T::seekdir * |
| 33 | ); |
| 34 | |
| 35 | template<typename T> |
| 36 | no_type check_is_iostream(...); |
| 37 | |
| 38 | template<typename T> |
| 39 | struct is_iostream |
| 40 | { |
| 41 | static bool const value = sizeof(yes_type) == sizeof(check_is_iostream<T>(0,0,0,0,0,0)); |
| 42 | typedef mpl::bool_<value> type; |
| 43 | }; |
| 44 | |
| 45 | /// INTERNAL ONLY |
| 46 | // This should be a customization point. And it serves the same purpose |
| 47 | // as the is_noncopyable trait in Boost.Foreach. |
| 48 | template<typename T> |
| 49 | struct is_noncopyable |
| 50 | : mpl::or_< |
| 51 | is_function<T> |
| 52 | , is_abstract<T> |
| 53 | , is_iostream<T> |
| 54 | , is_base_of<noncopyable, T> |
| 55 | > |
| 56 | {}; |
| 57 | |
| 58 | template<typename T, std::size_t N> |
| 59 | struct is_noncopyable<T[N]> |
| 60 | : mpl::true_ |
| 61 | {}; |
| 62 | |
| 63 | }}} |
| 64 | |
| 65 | #endif |
| 66 | |