Hypothetical, earlier C ++ 0x issues

( Preamble: I am a late follower of C ++ 0x, and recent debate about removing concepts from the C ++ 0x standard has prompted me to learn more about them. Although I understand that all my questions are completely hypothetical - since the concepts will not be valid C ++ -code for some time, if at all - I'm still interested in learning more about the concepts, especially considering how this will help, I understand in more detail the advantages of the recent solution and the contradictions that followed)

After reading some introductory materials on concepts, as C ++ 0x suggested them (until recently), I have problems with some syntax problems. Without further ado, here are my questions:

1) Will a type that supports a particular derived concept (either implicitly, via the auto keyword, or explicitly through concept_maps) also have to support the underlying concept unchanged? In other words, is it meant to get a concept from another (for example, concept B<typename T> : A<T> ) to include an "invisible" request (inside B, requires A<T>; )? Confusion arises on the Wikipedia page on concepts, which reads:

As with class inheritance, types that meet the requirements of a concept also meet the requirements of a basic concept.

It seems that the type should satisfy only derived conceptual requirements and optionally basic conceptual requirements, which makes no sense to me. I understand that Wikipedia is far from the final source; Is the above description just a bad choice of words?

2) Can a concept that lists type names be "auto"? If so, how does the compiler automatically match these types of names? If not, are there other cases where it would be wrong to use the β€œauto” in the concept?

To clarify, consider the following hypothetical code:

 template<typename Type> class Dummy {}; class Dummy2 { public: typedef int Type; }; auto concept SomeType<typename T> { typename Type; } template<typename T> requires SomeType<T> void function(T t) {} int main() { function(Dummy<int>()); //would this match SomeType? function(Dummy2()); //how about this? return 0; } 

Will any of these classes match SomeType? Or is the concept concept_map necessary for concepts with type names?

3) Finally, I can hardly understand which axioms can be defined. For example, is it possible to define a concept of an axiom that is logically incompatible, for example

 concept SomeConcept<typename T> { T operator*(T&, int); axiom Inconsistency(T a) { a * 1 == a * 2; } } 

What would it do? Is this even true?

I appreciate that this is a very long set of questions, and therefore I thank you in advance.

+11
c ++ c ++ 11 c ++ - axiom concepts
Jul 29 '09 at 20:06
source share
1 answer

I used the most recent C ++ 0x project, N2914 (which still contains the concept) as a reference for the next answer.

1) Concepts are like interfaces. If your type supports the concept, it should also support all the "basic" concepts. The Wikipedia statement that you are quoting makes sense from the point of view of a client like - if he knows that T satisfies the concept of Derived<T> , then he also knows that he satisfies the concept of Base<T> . From the point of view of the author, this naturally means that both of them must be implemented. See 14.10.3 / 2.

2) Yes, the concept with typename members can be auto . Such members can be automatically displayed if they are used in function member definitions in the same concept. For example, the value_type for an iterator can be inferred as the return type of its operator* . However, if a member of the type is not used anywhere, it will not be output and, therefore, will not be determined implicitly. In your example, there is no way to infer SomeType<T>::Type for Dummy or Dummy1 , since Type not used by other members of the concept, so no class will be displayed in the concept (and, in fact, no class could automatically display it) . See 14.10.1.2/11 and 14.10.2.2/4.

3) The axioms were a weak point of specification, and they were constantly updated to make some (more) sense. Shortly before the concepts were deleted from the draft, there was a paper that changed quite a bit - read it and see if you make sense, or if you still have questions about this.

In your specific example (given the syntactic difference), this would mean that the compiler would be allowed to consider the expression (a*1) as the same as (a*2) , for the purpose of the as-if rule of the language (ie the compiler allowed to do whatever optimizations he wants while the result behaves as if they weren't there). However, the compiler is in no way obligated to check the correctness of the axioms (therefore they are called axioms!) - he simply takes them for what they are.

+10
Jul 29 '09 at 20:28
source share



All Articles