Boost C++ 库

……世界上最受推崇且设计最专业的 C++ 库项目之一。 Herb SutterAndrei Alexandrescu,《C++ 编码规范

Boost 概念检查参考 - Boost C++ 函数库

参考

  1. 基础概念检查类
  2. 迭代器概念检查类
  3. 函数对象概念检查类
  4. 容器概念检查类
  5. 基础原型类
  6. 迭代器原型类
  7. 函数对象原型类
  8. 容器原型类
  9. 已弃用的函数
  10. 已弃用的宏
  11. 已弃用的概念检查类

#include "boost/concept/assert.hpp"

BOOST_CONCEPT_ASSERT((concept checking class template specialization));

效果:如果未满足概念,则导致编译失败。
注意:此宏可在全局、类或函数作用域中使用。

#include "boost/concept/requires.hpp"

template <…template parameters…>
BOOST_CONCEPT_REQUIRES(
  ((concept checking class template specialization1)) 
  ((concept checking class template specialization2))… 
  ((concept checking class template specializationn)),
  (function return type)
) function_template_name(…function parameters…)

效果:如果未满足给定概念,则导致编译失败。
注意:此宏旨在替代函数模板的返回类型使用。

基础概念检查类

#include "boost/concept_check.hpp"

template <class T>
struct Integer; // Is T a built-in integer type?

template <class T>
struct SignedInteger; // Is T a built-in signed integer type?

template <class T>
struct UnsignedInteger; // Is T a built-in unsigned integer type?

template <class X, class Y>
struct Convertible; // Is X convertible to Y?

template <class T>
struct Assignable; // Standard ref 23.1

template <class T>
struct SGIAssignable;

template <class T>
struct DefaultConstructible;

template <class T> 
struct CopyConstructible; // Standard ref 20.1.3

template <class T> 
struct EqualityComparable; // Standard ref 20.1.1

template <class T>
struct LessThanComparable; // Standard ref 20.1.2

template <class T>
struct Comparable; // The SGI STL LessThanComparable concept

迭代器概念检查类

template <class Iter>
struct InputIterator; // Standard ref 24.1.1 Table 72

template <class Iter, class T> 
struct OutputIterator; // Standard ref 24.1.2 Table 73

template <class Iter> 
struct ForwardIterator; // Standard ref 24.1.3 Table 74

template <class Iter> 
struct Mutable_ForwardIterator;

template <class Iter> 
struct BidirectionalIterator; // Standard ref 24.1.4 Table 75

template <class Iter> 
struct Mutable_BidirectionalIterator;

template <class Iter> 
struct RandomAccessIterator; // Standard ref 24.1.5 Table 76

template <class Iter> 
struct Mutable_RandomAccessIterator;

函数对象概念检查类

#include "boost/concept_check.hpp"

template <class Func, class Return>
struct Generator;

template <class Func, class Return, class Arg>
struct UnaryFunction;

template <class Func, class Return, class First, class Second>
struct BinaryFunction;

template <class Func, class Arg>
struct UnaryPredicate;

template <class Func, class First, class Second>
struct BinaryPredicate;

template <class Func, class First, class Second>
struct Const_BinaryPredicate;

template <class Func, class Return>
struct AdaptableGenerator;

template <class Func, class Return, class Arg>
struct AdaptableUnaryFunction;

template <class Func, class First, class Second>
struct AdaptableBinaryFunction;

template <class Func, class Arg>
struct AdaptablePredicate;

template <class Func, class First, class Second>
struct AdaptableBinaryPredicate;

容器概念检查类

#include "boost/concept_check.hpp"

template <class C>
struct Container; // Standard ref 23.1 Table 65

template <class C>
struct Mutable_Container;

template <class C>
struct ForwardContainer;

template <class C>
struct Mutable_ForwardContainer;

template <class C>
struct ReversibleContainer; // Standard ref 23.1 Table 66

template <class C>
struct Mutable_ReversibleContainer;

template <class C>
struct RandomAccessContainer;

template <class C>
struct Mutable_RandomAccessContainer;

template <class C>
struct Sequence; // Standard ref 23.1.1

template <class C>
struct FrontInsertionSequence;

template <class C>
struct BackInsertionSequence;

template <class C>
struct AssociativeContainer; // Standard ref 23.1.2 Table 69

template <class C>
struct UniqueAssociativeContainer;

template <class C>
struct MultipleAssociativeContainer;

template <class C>
struct SimpleAssociativeContainer;

template <class C>
struct PairAssociativeContainer;

template <class C>
struct SortedAssociativeContainer;

template <class C>
struct Collection;

基础原型类

#include "boost/concept_archetype.hpp"

template <class T = int>
class null_archetype; // A type that models no concepts.

template <class Base = null_archetype>
class default_constructible_archetype;

template <class Base = null_archetype>
class assignable_archetype;

template <class Base = null_archetype>
class copy_constructible_archetype;

template <class Base = null_archetype>
class equality_comparable_archetype;

template <class T, class Base = null_archetype>
class convertible_to_archetype;

迭代器原型类

#include "boost/concept_archetype.hpp"

template <class ValueType>
class trivial_iterator_archetype;

template <class ValueType>
class mutable_trivial_iterator_archetype;

template <class ValueType>
class input_iterator_archetype;

template <class ValueType>
class forward_iterator_archetype;

template <class ValueType>
class bidirectional_iterator_archetype;

template <class ValueType>
class random_access_iterator_archetype;

函数对象原型类

#include "boost/concept_archetype.hpp"

template <class Arg, class Return>
class unary_function_archetype;

template <class Arg1, class Arg2, class Return>
class binary_function_archetype;

template <class Arg>
class predicate_archetype;

template <class Arg1, class Arg2>
class binary_predicate_archetype;

容器原型类

UNDER CONSTRUCTION

已弃用的函数

#include "boost/concept_check.hpp"

template <class Concept>
void function_requires();

function_requires() 已被弃用,推荐使用 BOOST_CONCEPT_ASSERT。这意味着 function_requires< Concept >(); 改为 BOOST_CONCEPT_ASSERT((Concept));(别忘了 #include "boost/concept/assert.hpp")。

已弃用的宏

#include "boost/concept_check.hpp"

// Apply concept checks in class definitions.
BOOST_CLASS_REQUIRE(type, namespace-of-concept, concept);
BOOST_CLASS_REQUIRE2(type1, type2, namespace-of-concept, concept);
BOOST_CLASS_REQUIRE3(type1, type2, type3, namespace-of-concept, concept);
BOOST_CLASS_REQUIRE4(type1, type2, type3, type4, namespace-of-concept, concept);

// Apply concept checks in class definitions.
BOOST_CLASS_REQUIRES(type, concept);
BOOST_CLASS_REQUIRES2(type1, type2, concept);
BOOST_CLASS_REQUIRES3(type1, type2, type3, concept);
BOOST_CLASS_REQUIRES4(type1, type2, type3, type4, concept);

已弃用的概念检查类

对于本文档中列出的每个概念,库都提供了一个名称以 Concept 结尾的相同概念检查类。例如,除了 RandomAccessIterator,库还定义了一个 RandomAccessIteratorConcept 类模板。

返回介绍
上一步:实现

版权 © 2000 Jeremy Siek(jsiek@osl.iu.edu) Andrew Lumsdaine(lums@osl.iu.edu), 2007 David Abrahams.