![]() |
|
|||
File indexing completed on 2025-09-15 08:38:52
0001 /* 0002 * Distributed under the Boost Software License, Version 1.0. 0003 * (See accompanying file LICENSE_1_0.txt or copy at 0004 * https://www.boost.org/LICENSE_1_0.txt) 0005 * 0006 * Copyright (c) 2025 Andrey Semashev 0007 */ 0008 0009 #ifndef BOOST_ITERATOR_ENABLE_IF_CONVERTIBLE_HPP_INCLUDED_ 0010 #define BOOST_ITERATOR_ENABLE_IF_CONVERTIBLE_HPP_INCLUDED_ 0011 0012 #include <type_traits> 0013 0014 namespace boost { 0015 namespace iterators { 0016 namespace detail { 0017 0018 // 0019 // Result type used in enable_if_convertible meta function. 0020 // This can be an incomplete type, as only pointers to 0021 // enable_if_convertible< ... >::type are used. 0022 // We could have used void for this, but conversion to 0023 // void* is just too easy. 0024 // 0025 struct enable_type; 0026 0027 } // namespace detail 0028 0029 // 0030 // enable_if for use in adapted iterators constructors. 0031 // 0032 // In order to provide interoperability between adapted constant and 0033 // mutable iterators, adapted iterators will usually provide templated 0034 // conversion constructors of the following form 0035 // 0036 // template <class BaseIterator> 0037 // class adapted_iterator : 0038 // public iterator_adaptor< adapted_iterator<Iterator>, Iterator > 0039 // { 0040 // public: 0041 // 0042 // ... 0043 // 0044 // template <class OtherIterator> 0045 // adapted_iterator( 0046 // OtherIterator const& it 0047 // , typename enable_if_convertible<OtherIterator, Iterator>::type* = 0); 0048 // 0049 // ... 0050 // }; 0051 // 0052 // enable_if_convertible is used to remove those overloads from the overload 0053 // set that cannot be instantiated. For all practical purposes only overloads 0054 // for constant/mutable interaction will remain. This has the advantage that 0055 // meta functions like boost::is_convertible do not return false positives, 0056 // as they can only look at the signature of the conversion constructor 0057 // and not at the actual instantiation. 0058 // 0059 // enable_if_interoperable can be safely used in user code. It falls back to 0060 // always enabled for compilers that don't support enable_if or is_convertible. 0061 // There is no need for compiler specific workarounds in user code. 0062 // 0063 // The operators implementation relies on boost::is_convertible not returning 0064 // false positives for user/library defined iterator types. See comments 0065 // on operator implementation for consequences. 0066 // 0067 template< typename From, typename To > 0068 struct enable_if_convertible : 0069 public std::enable_if< 0070 std::is_convertible< From, To >::value, 0071 boost::iterators::detail::enable_type 0072 > 0073 {}; 0074 0075 template< typename From, typename To > 0076 using enable_if_convertible_t = typename enable_if_convertible< From, To >::type; 0077 0078 } // namespace iterators 0079 0080 using iterators::enable_if_convertible; 0081 0082 } // namespace boost 0083 0084 #endif // BOOST_ITERATOR_ENABLE_IF_CONVERTIBLE_HPP_INCLUDED_
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |