44

The C++ standards committee is working on a TS (Technical Specification) for Concepts extension: "Programming Languages - C++ Extensions for Concepts". N4377 is the latest version of this document. For inclusion into the C++ standard features are asked to be implemented, ideally for a publicly accessible system.

I'm aware of concept-gcc but the concepts proposal above (colloquially referred to as Concepts Lite) is different. I heard that there is a concepts branch and I have tried the origin/asutton/c++-concepts from gcc's git mirror but that didn't compile. How do I build and use a version of gcc supporting concepts as specified in the above [draft] TS?

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524
Dietmar Kühl
  • 150,225
  • 13
  • 225
  • 380
  • 1
    Should be tagged as "FAQ"? – Kerrek SB May 17 '15 at 18:02
  • 8
    Meta effect source: https://meta.stackoverflow.com/questions/294659/should-i-avoid-reviewing-altogether – Jeffrey Bosboom May 19 '15 at 18:16
  • 1
    @JeffreyBosboom: thank you very much for the pointer. It is an interesting read. Not that I think I had asked to find anything but rather for the existence of an implementation (and giving a "constructive proof" as answer) but I have reformulated the question to be in terms of a "problem" as advised in the text for off-topic questions. – Dietmar Kühl May 19 '15 at 22:04
  • 2
    Since I see a new close vote: can someone enlighten me what is wrong with the question now? It certainly doesn't ask a "find me ..." question as is indicated by the current close vote (nor did the original version, especially given that the answer posted already found that tool). I genuinely think the information in the answer and I'd change the question to be acceptable. – Dietmar Kühl May 20 '15 at 16:28
  • 6
    It is possible that voters haven't read your update closely. – JasonMArcher May 20 '15 at 17:46
  • 1
    Now it's "too broad" instead. Still not a very good question for Stack Overflow in my opinion. – Andrew May 21 '15 at 14:18
  • 1
    @AndrewArnold: this question is "broad" in which sense exactly? Can you suggest how to make it more specific? If you had said "too narrow" I might agree (although I don't; in fact, I still think the original question is useful and spot on). – Dietmar Kühl May 21 '15 at 14:21
  • 20
    **Please, refrain from downvoting/asking to close unless you understand how the C++ standarization process works, what is a TS and why it is important to have tools available to try the changes in the TS before it is standarized and forced unto all users** Having access to tools that can be used to detect inconsistencies in TS before it becomes standard and engraved in stone is of **uttermost importance**. This is **on-topic** for anyone interesting in the C++ tag. – David Rodríguez - dribeas May 21 '15 at 14:39
  • @DavidRodríguez-dribeas There is nothing in the SO guidelines that says its OK to ask for a tool "if its incredibly important for the standards process". The guidelines are very clear: "Questions asking us to .. find a .. tool .. are off-topic". This might not be a good guideline, but it is what we have. Fortunately the question avoids this issue now, but your bolded text is irrelevant in the assessment of a flag for "off topic due to asking for a tool". People have all sorts of reasons why they think their tool request should be allowed. I personally wish they were. But they aren't. – GreenAsJade May 22 '15 at 00:37
  • @GreenAsJade: Questions asking to **recommend** a tool. Is this such a question? Was it before? Consider [this](http://stackoverflow.com/questions/7232878/c11-compiler-closest-to-the-standard-and-how-close) or [this](http://stackoverflow.com/questions/9804594/compilers-that-support-c11) or [this](http://stackoverflow.com/questions/7966489/c11-compiler-for-windows). I understand that in other languages the language and the tool evolves from the same place, this is different in C++ (and C) where the language evolves and to test new features you need to find tools [...] – David Rodríguez - dribeas May 22 '15 at 07:50
  • [...] That is even more critical in situations like this, where we are talking about a feature that is not in the standard *yet*, but almost and for which experience has to be gained. There are different parts of the language that are suboptimal and would have been better had the community had time to try it. Concepts TS was created to gather that experience and improve the feature before it is standardized, the community **needs** to have implementations. Consider, if you may, the analogy of a guide dog. Do you want to play the fast rule, or would you let a guide dog in? – David Rodríguez - dribeas May 22 '15 at 07:55
  • 1
    @GreenAsJade: Have you read 5. *Questions about general computing hardware and **software are off-topic** for Stack Overflow **unless** they directly involve **tools used primarily for programming**.* -- How is a compiler not a tool for programming. Check the list of questions in this [answer](http://meta.stackoverflow.com/a/294991/36565) to your question in meta. How are they different? – David Rodríguez - dribeas May 22 '15 at 09:25
  • @DavidRodríguez-dribeas I think you misread the guidelines? It says questions asking to recommend or **find** a tool. Everyone can make an argument why their case deserves an exception to the rule. And this might be one. This doesn't make it "on topic", as you have asserted. If it is worth keeping despite being off topic, because it's important, that's a whole different request, and very valid. It's just important to be clear – GreenAsJade May 22 '15 at 09:25
  • I've spent a lot of time in the review queues, and have a keen interest in what is and is not really accepted. I can tell you for a fact that hundreds of questions *identical* in form to the orignal version of this question are closed every day. Questions about tools that are on topic are "what is this error message" or "how do I do this". Questions asking to recommend or find a tool are categorically out of scope, and are routinely closed. It's just how it is. The place to make a request for it to be different is meta. – GreenAsJade May 22 '15 at 09:27
  • @GreenAsJade: My point is that this is in the grey zone, you can argue both ways. People in the C++ community have deemed it interesting enough for 30 upvotes in the question and 15 to the answer, that has to have some weight. You might dislike that your flagging was rejected, but taking into consideration the votes is a **good** feature in SO. – David Rodríguez - dribeas May 22 '15 at 09:28
  • ... and do go ahead and close every other question I linked if they are against the rules. This is one of the few questions/answer from which I have got any value in the last year; even if you close it it is still visible due to my rep so that won't take the value away for me --it will for others. This is a community, and even if a particular decision hurts your feelings, the fact is that the community has reopened the question. Live with it. – David Rodríguez - dribeas May 22 '15 at 09:33
  • 1
    As a side note, Dietmar is one of the members in the standardization committee for C++, an active member of SO for over 3 years with a well above average reputation. I would expect that he has a feeling of whether something is relevant for C++ programmers in SO. – David Rodríguez - dribeas May 22 '15 at 09:38
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/78504/discussion-between-greenasjade-and-david-rodriguez-dribeas). – GreenAsJade May 22 '15 at 09:43
  • The accepted answer should be changed, given the updates noted in Yakk's response. @DietmarKühl – Phil Miller Jul 13 '17 at 17:18

2 Answers2

31

As of Fri, 7 Aug 2015 01:44:49 -0400 (05:44 +0000) concepts support has been merged into gcc's trunk.

Using a build from after that point, you can enable concepts support with the -std=c++1z flag.

As of gcc 6.1 (27-04-2016), concepts are enabled by -fconcepts as they are unlikely to be included in C++17, so they have been removed from -std=c++1z. (via @BruceAdams in comments below)

Yakk - Adam Nevraumont
  • 262,606
  • 27
  • 330
  • 524
  • 1
    Hello Yakk, it's great that gcc "has" concepts. I wonder if you could help me (plz) with this. I followed all instructions mentioned [here](http://www.linuxfromscratch.org/blfs/view/svn/general/gcc.html) and built gcc from its latest release (5.3) but source code with concepts fails to compile (for example [this](http://melpon.org/wandbox/permlink/xQC9StRPbGlHTV48)). I used the `-std=c++1z` flag but it looks like you're talking for an even newer version. Could you help me download that? – Lorah Attkins Dec 12 '15 at 15:29
  • 4
    As of gcc 6.1 (released 27-04-2106) concepts can be enabled with -fconcepts. The -std=c++1z is not appropriate any more as concepts are in a TS which is currently unlikely to be merged into C++17 (the TS vehicle allows implementation experience to be gained before standardising). – Bruce Adams Apr 28 '16 at 15:31
26

According to Andrew Sutton the git mirror of the Concepts Lite work is entirely out of date and shouldn't be used. There is a concepts branch in the svn repository for gcc implementing "concepts-lite" (there was a pre-C++11 effort to add concepts to C++ which was abandoned; a new effort to add concepts to C++ was started using the name concepts lite). It is fairly straight forward to build (assuming you already have a recent gcc and the packages it depends on installed; see the gcc install instruction for other options you might want to pass: the instructions below worked for me except that I explicitly pointed configure at the locations where gmp, mpc, and mpfr are installed):

cd <suitable-directory>
svn checkout svn://gcc.gnu.org/svn/gcc/branches/c++-concepts
mkdir build-concepts
cd build-concepts
../c++-concepts/configure --prefix=<concept-gcc-root> --disable-bootstrap --enable-languages=c,c++
make -j8
make install

What isn't entirely obvious is how to actually use concepts: the option -fconcepts does exist but seems to unconditionally do something different than enabling concepts-lite. Instead, you'd use the -std=c++1z option when compiling with concepts enabled.

Dietmar Kühl
  • 150,225
  • 13
  • 225
  • 380
  • 2
    Note to the reader: "concepts-lite" is the working title of the current "Concepts" extension for C++, to distinguish it from the now-abandoned concepts effort of the last decade (which is called "0x-concepts" if the distinction is required). – Kerrek SB May 17 '15 at 18:07
  • Thanks. That is appreciated. Any news when this will be merged into the main line? – Martin York May 17 '15 at 18:08
  • 1
    @LokiAstari: when I asked people about concepts support in gcc the general statement was that it would be merged "really soon" but no concrete date was given. This question is primarily intended to capture what I needed to find out on how to get hold of a concepts-enabled gcc. – Dietmar Kühl May 17 '15 at 18:11
  • 3
    @LokiAstari: People need to start playing with it to get experience (this question is very relevant for this) so that the approach can be test driven and ironed out. Bjarne has hopes (or rather is somehow determined) for this to be in C++17, but there are other people with concerns. Having access to a tool to do the actual test drive is **important** for the evolution of the language, and closing this question is a sad and quite unhelpful. – David Rodríguez - dribeas May 21 '15 at 14:15
  • 1
    @DavidRodríguez-dribeas: I think you addressed your comment to the wrong person. – Martin York May 21 '15 at 15:44
  • 10
    The concepts branch of gcc has been merged to trunk. – Eric Niebler Aug 08 '15 at 23:52
  • 2
    This answer needs to be updated to document gcc 6.1 behavior. – Janus Troelsen Jul 02 '16 at 02:09