123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- #ifndef BOOST_GEOMETRY_INDEX_INDEXABLE_HPP
- #define BOOST_GEOMETRY_INDEX_INDEXABLE_HPP
- #include <boost/tuple/tuple.hpp>
- #include <boost/geometry/core/static_assert.hpp>
- #include <boost/geometry/index/detail/is_indexable.hpp>
- #include <boost/geometry/util/type_traits.hpp>
- #include <tuple>
- namespace boost { namespace geometry { namespace index { namespace detail
- {
- template <typename From, typename To>
- struct is_referencable
- : std::is_same
- <
- typename util::remove_cref<From>::type,
- typename util::remove_cref<To>::type
- >
- {};
- template <typename Indexable, typename V>
- inline Indexable const& indexable_prevent_any_type(V const& )
- {
- BOOST_GEOMETRY_STATIC_ASSERT_FALSE("Unexpected type.", V);
- return Indexable();
- }
- template <typename Value, bool IsIndexable = is_indexable<Value>::value>
- struct indexable
- {
- BOOST_GEOMETRY_STATIC_ASSERT(
- (detail::is_indexable<Value>::value),
- "Value has to be an Indexable.",
- Value);
-
- typedef Value const& result_type;
-
- inline result_type operator()(Value const& v) const
- {
- return v;
- }
-
- template <typename V>
- inline result_type operator()(V const& v) const
- {
- return indexable_prevent_any_type<Value>(v);
- }
- };
- template <typename Indexable, typename Second>
- struct indexable<std::pair<Indexable, Second>, false>
- {
- typedef std::pair<Indexable, Second> value_type;
- BOOST_GEOMETRY_STATIC_ASSERT(
- (detail::is_indexable<Indexable>::value),
- "The first type of std::pair has to be an Indexable.",
- Indexable);
-
- typedef Indexable const& result_type;
-
- inline result_type operator()(value_type const& v) const
- {
- return v.first;
- }
-
- template <typename I, typename S>
- inline result_type operator()(std::pair<I, S> const& v) const
- {
- BOOST_GEOMETRY_STATIC_ASSERT(
- (is_referencable<I, result_type>::value),
- "Unexpected type.",
- std::pair<I, S>);
- return v.first;
- }
-
- template <typename V>
- inline result_type operator()(V const& v) const
- {
- return indexable_prevent_any_type<Indexable>(v);
- }
- };
- template <typename Value, typename Indexable>
- struct indexable_boost_tuple
- {
- typedef Value value_type;
- BOOST_GEOMETRY_STATIC_ASSERT(
- (detail::is_indexable<Indexable>::value),
- "The first type of boost::tuple has to be an Indexable.",
- Indexable);
-
- typedef Indexable const& result_type;
-
- inline result_type operator()(value_type const& v) const
- {
- return boost::get<0>(v);
- }
-
- template <typename I, typename U1, typename U2, typename U3, typename U4,
- typename U5, typename U6, typename U7, typename U8, typename U9>
- inline result_type operator()(boost::tuple<I, U1, U2, U3, U4, U5, U6, U7, U8, U9> const& v) const
- {
- BOOST_GEOMETRY_STATIC_ASSERT(
- (is_referencable<I, result_type>::value),
- "Unexpected type.",
- boost::tuple<I, U1, U2, U3, U4, U5, U6, U7, U8, U9>);
- return boost::get<0>(v);
- }
-
- template <typename I, typename T>
- inline result_type operator()(boost::tuples::cons<I, T> const& v) const
- {
- BOOST_GEOMETRY_STATIC_ASSERT(
- (is_referencable<I, result_type>::value),
- "Unexpected type.",
- boost::tuples::cons<I, T>);
- return boost::get<0>(v);
- }
-
- template <typename V>
- inline result_type operator()(V const& v) const
- {
- return indexable_prevent_any_type<Indexable>(v);
- }
- };
- template <typename Indexable, typename T1, typename T2, typename T3, typename T4,
- typename T5, typename T6, typename T7, typename T8, typename T9>
- struct indexable<boost::tuple<Indexable, T1, T2, T3, T4, T5, T6, T7, T8, T9>, false>
- : indexable_boost_tuple
- <
- boost::tuple<Indexable, T1, T2, T3, T4, T5, T6, T7, T8, T9>,
- Indexable
- >
- {};
- template <typename Indexable, typename Tail>
- struct indexable<boost::tuples::cons<Indexable, Tail>, false>
- : indexable_boost_tuple
- <
- boost::tuples::cons<Indexable, Tail>,
- Indexable
- >
- {};
- }}}}
- namespace boost { namespace geometry { namespace index { namespace detail {
- template <typename Indexable, typename ...Args>
- struct indexable<std::tuple<Indexable, Args...>, false>
- {
- typedef std::tuple<Indexable, Args...> value_type;
- BOOST_GEOMETRY_STATIC_ASSERT(
- (detail::is_indexable<Indexable>::value),
- "The first type of std::tuple has to be an Indexable.",
- Indexable);
-
- typedef Indexable const& result_type;
-
- result_type operator()(value_type const& v) const
- {
- return std::get<0>(v);
- }
-
- template <typename I, typename ...A>
- inline result_type operator()(std::tuple<I, A...> const& v) const
- {
- BOOST_GEOMETRY_STATIC_ASSERT(
- (is_referencable<I, result_type>::value),
- "Unexpected type.",
- std::tuple<I, A...>);
- return std::get<0>(v);
- }
-
- template <typename V>
- inline result_type operator()(V const& v) const
- {
- return indexable_prevent_any_type<Indexable>(v);
- }
- };
- }}}}
- namespace boost { namespace geometry { namespace index {
- template <typename Value>
- struct indexable
- : detail::indexable<Value>
- {
-
- typedef typename detail::indexable<Value>::result_type result_type;
-
- inline result_type operator()(Value const& v) const
- {
- return detail::indexable<Value>::operator()(v);
- }
-
- template <typename V>
- inline result_type operator()(V const& v) const
- {
- return detail::indexable<Value>::operator()(v);
- }
- };
- }}}
- #endif
|