问题
From what I remember C++ has concepts such as Mergable, Container, Comparable, Sortable, Arithmetic etc. I seen them here and there but I never seen a list. Where can I find a list of standard C++ concepts?
-edit- people are confused but what I mean is the example template line in this slide which has Container and Sortable. What else is there?
回答1:
Where can I find a list of standard C++ concepts?
Apparently, there isn't any, it didn't make it to the standard yet; see also Is the Committee Draft of Standard C++14 public? Nevertheless, the relevant documents seem to be Concepts Lite: Constraining Templates with Predicates (N3580) and A Concept Design for the STL (N3351). The list, as of Jun 15, 2014, taken from N3580:
Type Traits
- Equality_comparable
- Totally_ordered
- Movable
- Copyable
- Semiregular
- Regular
- Function
- Regular_function
- Predicate
- Relation
Iterator Concepts
- Iterator_category
- Value_type
- Difference_type
- Readable
- Writable
- Permutable
- Mutable
- Advanceable
- Incrementable
- Input_iterator
- Output_iterator
- Forward_iterator
- Bidirectional_iterator
- Random_access_itertor
Algorithm Constraints
- Indirectly_movable
- Indirectly_copyable
- Indirectly_swappable
- Indirectly_equal
- Indirectly_ordered
- Indirectly_comparable
- Sortable
- Mergeable
回答2:
From what I remember C++ has concepts such as Mergable, Container, Comparable, Sortable, Arithmetic etc. I seen them here and there but I never seen a list. Where can I find a list of standard C++ concepts?
What are concepts
Concepts are a term that refer to the formalization of type requirements that must be enforced by the compiler. This draft (N3580) contains all the details.
What are type requirements
Type requirements are a set of requirements, defined even in the C++03 standard, that must be enforced by the programmer in order to apply some operations on said type. The standard never call them concepts.
List of type requirements
I think you mean type requirements given that:
- you mentioned
Container
- you mentioned
Comparable
- the fact that you remember C++ has "concepts"
So, here's the list of type requirements in which you can also find Container
and Compare
(as organized by cppreference):
Basic
- DefaultConstructible
- MoveConstructible
- CopyConstructible
- MoveAssignable
- CopyAssignable
- Destructible
Layout
- TriviallyCopyable
- TrivialType
- StandardLayoutType
- PODType
Library-wide
- EqualityComparable
- LessThanComparable
- Swappable
- ValueSwappable
- NullablePointer
- Hash
- Allocator
- FunctionObject
- Callable
- Predicate
- BinaryPredicate
- Compare
Container
- Container
- ReversibleContainer
- AllocatorAwareContainer
- SequenceContainer
- AssociativeContainer
- UnorderedAssociativeContainer
Container element
- CopyInsertable
- MoveInsertable
- EmplaceConstructible
Iterator
- Iterator
- InputIterator
- OutputIterator
- ForwardIterator
- BidirectionalIterator
- RandomAccessIterator
Stream I/O functions
- UnformattedInputFunction
- FormattedInputFunction
- UnformattedOutputFunction
- FormattedOutputFunction
Random Number Generator
- SeedSequence
- UniformRandomNumberGenerator
- RandomNumberEngine
- RandomNumberEngineAdaptor
- RandomNumberDistribution
Concurrency
- BasicLockable
- Lockable
- TimedLockable
- Mutex
- TimedMutex
- SharedTimedMutex
Other
- UnaryTypeTrait
- BinaryTypeTrait
- TransformationTrait
- Clock
- TrivialClock
- CharTraits
- pos_type
- off_type
- BitmaskType
- LiteralType
回答3:
Briefly, a "concept is a set of requirements consisting of valid expressions, associated types, invariants, and complexity guarantees. A type that satisfies the requirements is said to model the concept. A concept can extend the requirements of another concept, which is called refinement."
Source: http://www.boost.org/community/generic_programming.html#concept
There are several concepts lists available:
- http://en.cppreference.com/w/cpp/concept
// to my knowledge this one is most complete - https://www.sgi.com/tech/stl/table_of_contents.html
// note: this is pre-standard, but the descriptions are informative and also apply to the concepts existing today - http://www.generic-programming.org/languages/conceptcpp/concept_web.php
For further explanation, see "Concepts and Modeling" as well as "Refinement" in the following: https://www.sgi.com/tech/stl/stl_introduction.html
See also:
- https://www.sgi.com/tech/stl/doc_introduction.html
- http://www.generic-programming.org/about/intro/concepts.php
- http://www.generic-programming.org/languages/conceptcpp/specification/
You may also be interested in:
- The Boost Concept Check Library (BCCL): http://www.boost.org/doc/libs/master/libs/concept_check/concept_check.htm
- New Iterator Concepts: http://www.boost.org/doc/libs/master/libs/iterator/doc/new-iter-concepts.html
来源:https://stackoverflow.com/questions/24228648/list-of-standard-concepts