Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
Front Page / Sequences / Intrinsic Metafunctions / has_key

has_key

Synopsis

template<
      typename Sequence
    , typename Key
    >
struct has_key
{
    typedef unspecified type;
};

Description

Returns a true-valued Integral Constant if Sequence contains an element with key Key.

Header

#include <boost/mpl/has_key.hpp>

Model of

Tag Dispatched Metafunction

Parameters

Parameter Requirement Description
Sequence Associative Sequence A sequence to query.
Key Any type The queried key.

Expression semantics

For any Associative Sequence s, and arbitrary type key:

typedef has_key<s,key>::type c; 
Return type:Boolean Integral Constant.
Semantics:c::value == true if key is in s's set of keys; otherwise c::value == false.

Complexity

Amortized constant time.

Example

typedef map< pair<int,unsigned>, pair<char,long> > m;
BOOST_MPL_ASSERT_NOT(( has_key<m,long> ));

typedef insert< m, pair<long,unsigned long> > m1;
BOOST_MPL_ASSERT(( has_key<m1,long> ));

See also

Associative Sequence, count, insert, erase_key