Chris@16: // Boost.Bimap Chris@16: // Chris@16: // Copyright (c) 2006-2007 Matias Capeletto Chris@16: // Chris@16: // Distributed under the Boost Software License, Version 1.0. Chris@16: // (See accompanying file LICENSE_1_0.txt or copy at Chris@16: // http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: /// \file unordered_set_of.hpp Chris@16: /// \brief Include support for unordered_set constrains for the bimap container Chris@16: Chris@16: #ifndef BOOST_BIMAP_UNORDERED_SET_OF_HPP Chris@16: #define BOOST_BIMAP_UNORDERED_SET_OF_HPP Chris@16: Chris@101: #if defined(_MSC_VER) Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace bimaps { Chris@16: Chris@16: /// \brief Set Type Specification Chris@16: /** Chris@16: This struct is used to specify an unordered_set specification. Chris@16: It is not a container, it is just a metaprogramming facility to Chris@16: express the type of a set. Generally, this specification will Chris@16: be used in other place to create a container. Chris@16: It has the same syntax that an tr1::unordered_set instantiation, Chris@16: except that the allocator cannot be specified. The rationale behind Chris@16: this difference is that the allocator is not part of the Chris@16: unordered_set type specification, rather it is a container Chris@16: configuration parameter. Chris@16: The first parameter is the type of the objects in the set, the Chris@16: second one is a Hash Functor that takes objects of this type, and Chris@16: the third one is a Functor that compares them for equality. Chris@16: Bimap binding metafunctions can be used with this class in Chris@16: the following way: Chris@16: Chris@16: \code Chris@16: using namespace support; Chris@16: Chris@16: BOOST_STATIC_ASSERT( is_set_type_of< unordered_set_of >::value ) Chris@16: Chris@16: BOOST_STATIC_ASSERT Chris@16: ( Chris@16: is_same Chris@16: < Chris@16: unordered_set_of::index_bind Chris@16: < Chris@16: KeyExtractor, Chris@16: Tag Chris@16: Chris@16: >::type, Chris@16: Chris@16: hashed_unique< tag, KeyExtractor, HashFunctor, EqualKey > Chris@16: Chris@16: >::value Chris@16: ) Chris@16: Chris@16: typedef bimap Chris@16: < Chris@16: unordered_set_of, RightKeyType Chris@16: Chris@16: > bimap_with_left_type_as_unordered_set; Chris@16: Chris@16: BOOST_STATIC_ASSERT Chris@16: ( Chris@16: is_same Chris@16: < Chris@16: unordered_set_of::map_view_bind Chris@16: < Chris@16: member_at::left, Chris@16: bimap_with_left_type_as_unordered_set Chris@16: Chris@16: >::type, Chris@16: Chris@16: unordered_map_view Chris@16: < Chris@16: member_at::left, Chris@16: bimap_with_left_type_as_unordered_set Chris@16: > Chris@16: Chris@16: >::value Chris@16: ) Chris@16: Chris@16: \endcode Chris@16: Chris@16: See also unordered_set_of_relation. Chris@16: **/ Chris@16: Chris@16: template Chris@16: < Chris@16: class KeyType, Chris@16: class HashFunctor = hash< BOOST_DEDUCED_TYPENAME Chris@16: ::boost::bimaps::tags::support::value_type_of::type >, Chris@16: class EqualKey = std::equal_to< BOOST_DEDUCED_TYPENAME Chris@16: ::boost::bimaps::tags::support::value_type_of::type > Chris@16: > Chris@16: struct unordered_set_of : public ::boost::bimaps::detail::set_type_of_tag Chris@16: { Chris@16: /// User type, can be tagged Chris@16: typedef KeyType user_type; Chris@16: Chris@16: /// Type of the object that will be stored in the container Chris@16: typedef BOOST_DEDUCED_TYPENAME ::boost::bimaps::tags::support:: Chris@16: value_type_of::type value_type; Chris@16: Chris@16: /// Hash Functor that takes value_type objects Chris@16: typedef HashFunctor hasher; Chris@16: Chris@16: /// Functor that compare two value_type objects for equality Chris@16: typedef EqualKey key_equal; Chris@16: Chris@16: struct lazy_concept_checked Chris@16: { Chris@16: BOOST_CLASS_REQUIRE ( value_type, Chris@16: boost, AssignableConcept ); Chris@16: Chris@16: BOOST_CLASS_REQUIRE3( hasher, std::size_t, value_type, Chris@16: boost, UnaryFunctionConcept ); Chris@16: Chris@16: BOOST_CLASS_REQUIRE4( key_equal, bool, value_type, value_type, Chris@16: boost, BinaryFunctionConcept ); Chris@16: Chris@16: typedef unordered_set_of type; Chris@16: }; Chris@16: Chris@16: BOOST_BIMAP_GENERATE_INDEX_BINDER_2CP( Chris@16: Chris@16: // binds to Chris@16: multi_index::hashed_unique, Chris@16: Chris@16: // with Chris@16: hasher, Chris@16: key_equal Chris@16: ) Chris@16: Chris@16: BOOST_BIMAP_GENERATE_MAP_VIEW_BINDER( Chris@16: Chris@16: // binds to Chris@16: views::unordered_map_view Chris@16: ) Chris@16: Chris@16: BOOST_BIMAP_GENERATE_SET_VIEW_BINDER( Chris@16: Chris@16: // binds to Chris@16: views::unordered_set_view Chris@16: ) Chris@16: Chris@16: typedef mpl::bool_ mutable_key; Chris@16: }; Chris@16: Chris@16: Chris@16: /// \brief Set Of Relation Specification Chris@16: /** Chris@16: This struct is similar to unordered_set_of but it is bind logically to Chris@16: a relation. It is used in the bimap instantiation to specify the Chris@16: desired type of the main view. This struct implements internally Chris@16: a metafunction named bind_to that manages the quite complicated Chris@16: task of finding the right type of the set for the relation. Chris@16: Chris@16: \code Chris@16: template Chris@16: struct bind_to Chris@16: { Chris@16: typedef -unspecified- type; Chris@16: }; Chris@16: \endcode Chris@16: Chris@16: See also unordered_set_of, is_set_type_of_relation. Chris@16: **/ Chris@16: Chris@16: template Chris@16: < Chris@16: class HashFunctor = hash< _relation >, Chris@16: class EqualKey = std::equal_to< _relation > Chris@16: > Chris@16: struct unordered_set_of_relation : public ::boost::bimaps::detail::set_type_of_relation_tag Chris@16: { Chris@16: /// Hash Functor that takes value_type objects Chris@16: typedef HashFunctor hasher; Chris@16: Chris@16: /// Functor that compare two value_type objects for equality Chris@16: typedef EqualKey key_equal; Chris@16: Chris@16: Chris@16: BOOST_BIMAP_GENERATE_RELATION_BINDER_2CP( Chris@16: Chris@16: // binds to Chris@16: unordered_set_of, Chris@16: Chris@16: // with Chris@16: hasher, Chris@16: key_equal Chris@16: ) Chris@16: Chris@16: typedef mpl::bool_ left_mutable_key; Chris@16: typedef mpl::bool_ right_mutable_key; Chris@16: }; Chris@16: Chris@16: Chris@16: } // namespace bimaps Chris@16: } // namespace boost Chris@16: Chris@16: Chris@16: #endif // BOOST_BIMAP_UNORDERED_SET_OF_HPP Chris@16: