tagged.hpp
字号:
// Boost.Bimap//// Copyright (c) 2006-2007 Matias Capeletto//// 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)/// \file tags/tagged.hpp/// \brief Defines the tagged class#ifndef BOOST_BIMAP_TAGS_TAGGED_HPP#define BOOST_BIMAP_TAGS_TAGGED_HPP#if defined(_MSC_VER) && (_MSC_VER>=1200)#pragma once#endif#include <boost/config.hpp>namespace boost {namespace bimaps {/// \brief A light non-invasive idiom to tag a type./**There are a lot of ways of tagging a type. The standard library for exampledefines tags (empty structs) that are then inherited by the tagged class. Tosupport built-in types and other types that simple cannot inherit from thetag, the standard builds another level of indirection. An example of this isthe type_traits metafunction. This approach is useful if the tags are intendedto be used in the library internals, and if the user does not have to createnew tagged types often.Boost.MultiIndex is an example of a library that defines a tagged idiom thatis better suited to the user. As an option, in the indexed by declarationof a multi-index container a user can \b attach a tag to each index, so itcan be referred by it instead of by the index number. It is a very userfriendly way of specifying a tag but is very invasive from the library writer'spoint of view. Each index must now support this additional parameter. Maybenot in the case of the multi-index container, but in simpler classesthe information of the tags is used by the father class rather than by thetagged types.\b tagged is a light non-invasive idiom to tag a type. It is very intuitiveand user-friendly. With the use of the defined metafunctions the librarywriter can enjoy the coding too. **/namespace tags {/// \brief The tag holder/**The idea is to add a level of indirection to the type being tagged. With thisclass you wrapped a type and apply a tag to it. The only thing to remember isthat if you write\codetypedef tagged<type,tag> taggedType;\endcodeThen instead to use directly the tagged type, in order to access it you haveto write \c taggedType::value_type. The tag can be obtained using \c taggedType::tag.The idea is not to use this metadata directly but rather using the metafunctionsthat are defined in the support namespace. With this metafunctions you can workwith tagged and untagged types in a consistent way. For example, the followingcode is valid:\codeBOOST_STATIC_ASSERT( is_same< value_type_of<taggedType>, value_type_of<type> >::value );\endcodeThe are other useful metafunctions there too.See also value_type_of, tag_of, is_tagged, apply_to_value_type.\ingroup tagged_group **/template< class Type, class Tag >struct tagged{ typedef Type value_type; typedef Tag tag;};} // namespace tags} // namespace bimaps} // namespace boost/** \namespace boost::bimaps::tags::support\brief Metafunctions to work with tagged types.This metafunctions aims to make easier the manage of tagged types. They are all mplcompatible metafunctions and can be used with lambda expresions.The metafunction value_type_of and tag_of get the data in a tagged type in a secureand consistent way.default_tagged and overwrite_tagged allows to work with the tag of a tagged type,and apply_to_value_type is a higher order metafunction that allow the user to changethe type of a TaggedType. **/#endif // BOOST_BIMAP_TAGS_TAGGED_HPP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -