Boost C++ Libraries 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.

Key-value flyweights reference


Key extractors

Let Key be a type with some implicit equivalence relationship and Value a type constructible from Key. A Default Constructible type KeyFromValue is said to be a key extractor from Value to Key if

  1. kfv(cv) is defined and have type const Key&,
  2. kfv(cv) is equivalent to kfv(Value(cv)),
  3. kfv(Value(k)) is equivalent to k,
for every kfv of type const KeyFromValue, cv of type const Value and k of type Key.

Header "boost/flyweight/key_value_fwd.hpp" synopsis

namespace boost{

namespace flyweights{

struct no_key_from_value;

  typename Key,typename Value,
  typename KeyFromValue=no_key_from_value
struct key_value;

} // namespace boost::flyweights

} // namespace boost

Header "boost/flyweight/key_value.hpp" synopsis

Class template key_value

In flyweight instantiations of the form flyweight<T,...>, the associated key_type and value_type are both equal to T. Instantiations of the form flyweight<key_value<Key,Value[,KeyFromValue]>,...> allow to specify these types separately. Key and Value must be different types. When provided, KeyFromValue must be a Key Extractor from Value to Key.

Revised September 15th 2008

© Copyright 2006-2008 Joaquín M López Muñoz. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at