/usr/include/boost/container
Edit: /usr/include/boost/container/map.hpp (103528B)
//////////////////////////////////////////////////////////////////////////////
//
// (C) Copyright Ion Gaztanaga 2005-2013. Distributed under the Boost
// Software License, Version 1.0. (See accompanying file
// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// See http://www.boost.org/libs/container for documentation.
//
//////////////////////////////////////////////////////////////////////////////
#ifndef BOOST_CONTAINER_MAP_HPP
#define BOOST_CONTAINER_MAP_HPP
#ifndef BOOST_CONFIG_HPP
# include
#endif
#if defined(BOOST_HAS_PRAGMA_ONCE)
# pragma once
#endif
#include
#include
// container
#include
#include //new_allocator
#include
// container/detail
#include
#include
#include
#include
#include
#include
// move
#include
#include
// move/detail
#if defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
#include
#endif
#include
// intrusive/detail
#include //pair
#include //less, equal
// other
#include
#include
// std
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
#include
#endif
namespace boost {
namespace container {
#ifdef BOOST_CONTAINER_DOXYGEN_INVOKED
//! A map is a kind of associative container that supports unique keys (contains at
//! most one of each key value) and provides for fast retrieval of values of another
//! type T based on the keys. The map class supports bidirectional iterators.
//!
//! A map satisfies all of the requirements of a container and of a reversible
//! container and of an associative container. The value_type stored
//! by this container is the value_type is std::pair.
//!
//! \tparam Key is the key_type of the map
//! \tparam T is the mapped_type
//! \tparam Compare is the ordering function for Keys (e.g. std::less).
//! \tparam Allocator is the allocator to allocate the value_types
//! (e.g. allocator< std::pair > ).
//! \tparam Options is an packed option type generated using using boost::container::tree_assoc_options.
template < class Key, class T, class Compare = std::less
, class Allocator = void, class Options = tree_assoc_defaults >
#else
template
#endif
class map
///@cond
: public dtl::tree
< std::pair
, int
, Compare, Allocator, Options>
///@endcond
{
#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
private:
BOOST_COPYABLE_AND_MOVABLE(map)
typedef int select_1st_t;
typedef std::pair value_type_impl;
typedef dtl::tree
base_t;
typedef dtl::pair movable_value_type_impl;
typedef typename base_t::value_compare value_compare_impl;
#endif //#ifndef BOOST_CONTAINER_DOXYGEN_INVOKED
public:
//////////////////////////////////////////////
//
// types
//
//////////////////////////////////////////////
typedef Key key_type;
typedef T mapped_type;
typedef typename base_t::allocator_type allocator_type;
typedef ::boost::container::allocator_traits allocator_traits_type;
typedef typename boost::container::allocator_traits::value_type value_type;
typedef typename boost::container::allocator_traits::pointer pointer;
typedef typename boost::container::allocator_traits::const_pointer const_pointer;
typedef typename boost::container::allocator_traits::reference reference;
typedef typename boost::container::allocator_traits::const_reference const_reference;
typedef typename boost::container::allocator_traits::size_type size_type;
typedef typename boost::container::allocator_traits::difference_type difference_type;
typedef typename BOOST_CONTAINER_IMPDEF(base_t::stored_allocator_type) stored_allocator_type;
typedef BOOST_CONTAINER_IMPDEF(value_compare_impl) value_compare;
typedef Compare key_compare;
typedef typename BOOST_CONTAINER_IMPDEF(base_t::iterator) iterator;
typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_iterator) const_iterator;
typedef typename BOOST_CONTAINER_IMPDEF(base_t::reverse_iterator) reverse_iterator;
typedef typename BOOST_CONTAINER_IMPDEF(base_t::const_reverse_iterator) const_reverse_iterator;
typedef std::pair nonconst_value_type;
typedef BOOST_CONTAINER_IMPDEF(movable_value_type_impl) movable_value_type;
typedef BOOST_CONTAINER_IMPDEF(node_handle<
typename base_t::stored_allocator_type
BOOST_MOVE_I pair_key_mapped_of_value
>) node_type;
typedef BOOST_CONTAINER_IMPDEF
(insert_return_type_base) insert_return_type;
//allocator_type::value_type type must be std::pair
BOOST_STATIC_ASSERT((dtl::is_same >::value));
//////////////////////////////////////////////
//
// construct/copy/destroy
//
//////////////////////////////////////////////
//! Effects: Default constructs an empty map.
//!
//! Complexity: Constant.
BOOST_CONTAINER_FORCEINLINE
map() BOOST_NOEXCEPT_IF(dtl::is_nothrow_default_constructible::value &&
dtl::is_nothrow_default_constructible::value)
: base_t()
{}
//! Effects: Constructs an empty map using the specified comparison object
//! and allocator.
//!
//! Complexity: Constant.
BOOST_CONTAINER_FORCEINLINE map(const Compare& comp, const allocator_type& a)
: base_t(comp, a)
{}
//! Effects: Constructs an empty map using the specified comparison object.
//!
//! Complexity: Constant.
BOOST_CONTAINER_FORCEINLINE explicit map(const Compare& comp)
: base_t(comp)
{}
//! Effects: Constructs an empty map using the specified allocator.
//!
//! Complexity: Constant.
BOOST_CONTAINER_FORCEINLINE explicit map(const allocator_type& a)
: base_t(a)
{}
//! Effects: Constructs an empty map and
//! inserts elements from the range [first ,last ).
//!
//! Complexity: Linear in N if the range [first ,last ) is already sorted using
//! the predicate and otherwise N logN, where N is last - first.
template
BOOST_CONTAINER_FORCEINLINE map(InputIterator first, InputIterator last)
: base_t(true, first, last)
{}
//! Effects: Constructs an empty map using the specified
//! allocator, and inserts elements from the range [first ,last ).
//!
//! Complexity: Linear in N if the range [first ,last ) is already sorted using
//! the predicate and otherwise N logN, where N is last - first.
template
BOOST_CONTAINER_FORCEINLINE map(InputIterator first, InputIterator last, const allocator_type& a)
: base_t(true, first, last, Compare(), a)
{}
//! Effects: Constructs an empty map using the specified comparison object and
//! inserts elements from the range [first ,last ).
//!
//! Complexity: Linear in N if the range [first ,last ) is already sorted using
//! the predicate and otherwise N logN, where N is last - first.
template
BOOST_CONTAINER_FORCEINLINE map(InputIterator first, InputIterator last, const Compare& comp)
: base_t(true, first, last, comp)
{}
//! Effects: Constructs an empty map using the specified comparison object and
//! allocator, and inserts elements from the range [first ,last ).
//!
//! Complexity: Linear in N if the range [first ,last ) is already sorted using
//! the predicate and otherwise N logN, where N is last - first.
template
BOOST_CONTAINER_FORCEINLINE map(InputIterator first, InputIterator last, const Compare& comp, const allocator_type& a)
: base_t(true, first, last, comp, a)
{}
//! Effects: Constructs an empty map and
//! inserts elements from the ordered unique range [first ,last). This function
//! is more efficient than the normal range creation for ordered ranges.
//!
//! Requires: [first ,last) must be ordered according to the predicate and must be
//! unique values.
//!
//! Complexity: Linear in N.
//!
//! Note: Non-standard extension.
template
BOOST_CONTAINER_FORCEINLINE map( ordered_unique_range_t, InputIterator first, InputIterator last)
: base_t(ordered_range, first, last)
{}
//! Effects: Constructs an empty map using the specified comparison object and
//! inserts elements from the ordered unique range [first ,last). This function
//! is more efficient than the normal range creation for ordered ranges.
//!
//! Requires: [first ,last) must be ordered according to the predicate and must be
//! unique values.
//!
//! Complexity: Linear in N.
//!
//! Note: Non-standard extension.
template
BOOST_CONTAINER_FORCEINLINE map( ordered_unique_range_t, InputIterator first, InputIterator last, const Compare& comp)
: base_t(ordered_range, first, last, comp)
{}
//! Effects: Constructs an empty map using the specified comparison object and
//! allocator, and inserts elements from the ordered unique range [first ,last). This function
//! is more efficient than the normal range creation for ordered ranges.
//!
//! Requires: [first ,last) must be ordered according to the predicate and must be
//! unique values.
//!
//! Complexity: Linear in N.
//!
//! Note: Non-standard extension.
template
BOOST_CONTAINER_FORCEINLINE map( ordered_unique_range_t, InputIterator first, InputIterator last
, const Compare& comp, const allocator_type& a)
: base_t(ordered_range, first, last, comp, a)
{}
//! Effects: Constructs an empty map using the specified allocator object and
//! inserts elements from the ordered unique range [first ,last). This function
//! is more efficient than the normal range creation for ordered ranges.
//!
//! Requires: [first ,last) must be ordered according to the predicate and must be
//! unique values.
//!
//! Complexity: Linear in N.
//!
//! Note: Non-standard extension.
template
BOOST_CONTAINER_FORCEINLINE map(ordered_unique_range_t, InputIterator first, InputIterator last, const allocator_type& a)
: base_t(ordered_range, first, last, Compare(), a)
{}
#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
//! Effects: Constructs an empty map and
//! inserts elements from the range [il.begin(), il.end()).
//!
//! Complexity: Linear in N if the range [first ,last ) is already sorted according
//! to the predicate and otherwise N logN, where N is il.first() - il.end().
BOOST_CONTAINER_FORCEINLINE map(std::initializer_list il)
: base_t(true, il.begin(), il.end())
{}
//! Effects: Constructs an empty map using the specified comparison object and
//! inserts elements from the range [il.begin(), il.end()).
//!
//! Complexity: Linear in N if the range [first ,last ) is already sorted using
//! the predicate and otherwise N logN, where N is il.first() - il.end().
BOOST_CONTAINER_FORCEINLINE map(std::initializer_list il, const Compare& comp)
: base_t(true, il.begin(), il.end(), comp)
{}
//! Effects: Constructs an empty map using the specified
//! allocator, and inserts elements from the range [il.begin(), il.end()).
//!
//! Complexity: Linear in N if the range [first ,last ) is already sorted using
//! the predicate and otherwise N logN, where N is il.first() - il.end().
BOOST_CONTAINER_FORCEINLINE map(std::initializer_list il, const allocator_type& a)
: base_t(true, il.begin(), il.end(), Compare(), a)
{}
//! Effects: Constructs an empty map using the specified comparison object and
//! allocator, and inserts elements from the range [il.begin(), il.end()).
//!
//! Complexity: Linear in N if the range [first ,last ) is already sorted using
//! the predicate and otherwise N logN, where N is il.first() - il.end().
BOOST_CONTAINER_FORCEINLINE map(std::initializer_list il, const Compare& comp, const allocator_type& a)
: base_t(true, il.begin(), il.end(), comp, a)
{}
//! Effects: Constructs an empty map and inserts elements from the ordered unique range [il.begin(), il.end()).
//! This function is more efficient than the normal range creation for ordered ranges.
//!
//! Requires: [il.begin(), il.end()) must be ordered according to the predicate and must be
//! unique values.
//!
//! Complexity: Linear in N.
//!
//! Note: Non-standard extension.
BOOST_CONTAINER_FORCEINLINE map(ordered_unique_range_t, std::initializer_list il)
: base_t(ordered_range, il.begin(), il.end())
{}
//! Effects: Constructs an empty map using the specified comparison object,
//! and inserts elements from the ordered unique range [il.begin(), il.end()). This function
//! is more efficient than the normal range creation for ordered ranges.
//!
//! Requires: [il.begin(), il.end()) must be ordered according to the predicate and must be
//! unique values.
//!
//! Complexity: Linear in N.
//!
//! Note: Non-standard extension.
BOOST_CONTAINER_FORCEINLINE map(ordered_unique_range_t, std::initializer_list il, const Compare& comp)
: base_t(ordered_range, il.begin(), il.end(), comp)
{}
//! Effects: Constructs an empty map using the specified comparison object and
//! allocator, and inserts elements from the ordered unique range [il.begin(), il.end()). This function
//! is more efficient than the normal range creation for ordered ranges.
//!
//! Requires: [il.begin(), il.end()) must be ordered according to the predicate and must be
//! unique values.
//!
//! Complexity: Linear in N.
//!
//! Note: Non-standard extension.
BOOST_CONTAINER_FORCEINLINE map( ordered_unique_range_t, std::initializer_list il
, const Compare& comp, const allocator_type& a)
: base_t(ordered_range, il.begin(), il.end(), comp, a)
{}
#endif
//! Effects: Copy constructs a map.
//!
//! Complexity: Linear in x.size().
BOOST_CONTAINER_FORCEINLINE map(const map& x)
: base_t(static_cast(x))
{}
//! Effects: Move constructs a map. Constructs *this using x's resources.
//!
//! Complexity: Constant.
//!
//! Postcondition: x is emptied.
BOOST_CONTAINER_FORCEINLINE map(BOOST_RV_REF(map) x)
BOOST_NOEXCEPT_IF(boost::container::dtl::is_nothrow_move_constructible::value)
: base_t(BOOST_MOVE_BASE(base_t, x))
{}
//! Effects: Copy constructs a map using the specified allocator.
//!
//! Complexity: Linear in x.size().
BOOST_CONTAINER_FORCEINLINE map(const map& x, const allocator_type &a)
: base_t(static_cast(x), a)
{}
//! Effects: Move constructs a map using the specified allocator.
//! Constructs *this using x's resources.
//!
//! Complexity: Constant if x == x.get_allocator(), linear otherwise.
//!
//! Postcondition: x is emptied.
BOOST_CONTAINER_FORCEINLINE map(BOOST_RV_REF(map) x, const allocator_type &a)
: base_t(BOOST_MOVE_BASE(base_t, x), a)
{}
//! Effects: Makes *this a copy of x.
//!
//! Complexity: Linear in x.size().
BOOST_CONTAINER_FORCEINLINE map& operator=(BOOST_COPY_ASSIGN_REF(map) x)
{ return static_cast