I am working on a class project which uses C++ concepts. Where can I find an STL implementation that supports has constraints from the concepts draft TS, such as Equality_comparable or Sortable?
Thanks for your help!
Here's what I tried so far:
I've successfully compiled the c++-concepts branch from GCC's SVN, which appears to be maintained (last updated yesterday by Andrew Sutton). However, the libstdc++ that comes with this branch has not been updated for concepts.
I also tried Concepts-Lite (gcc-clite), which promises:
The standard library shipping with this compiler includes the constraints found in the paper "A Concept Design for the STL", which can be accessed by including the <type_traits> header file.
However, libstdc++ in the GCC code downloaded from that page also does not have concepts. In particular, the type_traits header appears to be unchanged from the GCC revision it was forked from.
Have a look at Andrew Sutton's Origin library on github. If you follow the origin/core directory you can find the basic concepts. He has some graph, math, and some container stuff stuff too from the look of it.
I have to admit that I'm in the middle of exploring this myself so I have no intelligent report yet.
Only downside: the most recent check-ins are a couple of months or more ago. I guess we'll see.
Related
When the C++ committee publish a new feature that will be part of the standard library in the next standard of the language, do they also release some source code or some kind of guidance on how to implement that feature?
Let's take unique_ptr as an example. The language committee just defines an interface for that class template and let the compiler vendor implement it as it wants? How exactly does this process of implementation of the standard library features occur?
Can anyone implement parts of the standard library for a platform that doesn't have support for them yet? Let say I would like to implement some cool features of the C++ standard library to use it on a microcontroller environment. How could I do that? Where should I look for information? If I decide to open source my project, can I do that? Will I need to follow exactly what the standard says, or I can write a non-compliant version?
Usually,
every new library feature goes through a proposal.
If the proposal makes it to the C++ committee's Library Evolution Working Group, it goes through a series of iterations (a "tough ground" as I am aware).
It undergoes a series of refinement process as described here
Should it require a (TS) Technical Specification (since C++11), it goes there to be baked. Take for example, the #include <filesystem> was in a Filesystem TS prior to C++17.
One thing I believe the committee likes, is an implementation experience.
More information can be found on the ISOCpp site
Well, as to the implementation:
There are quite a number of "library features" that cannot be implemented purely as a library. they require compiler support. And in these case, compilers provides "intrinsic" that you could hook on to. Take for example, clang provides intrinsics for certain type_traits
Most library features have some implementation experience, mostly from the Boost libraries.
You could actually look into the source code for the default standard library that ships with your compiler:
libc++ for Clang
libstdc++ for GCC
Sadly most of the implementations use a whole bunch of underscores. Mostly because they are reserved for use by the "Standard Library".
Can anyone implement parts of the standard library for a platform that doesn't have support for it yet?
Yes, you can, so far your compiler supports that platform, and the platform or Operating System provides usable API. For example. std::cout, elements of std::ifstream, and so much more requires platform specific support.
Let say I would like to implement some cool features of the C++ standard library to use it on a microcontroller environment. How could I do that?
You can look into the code of others and start from there. We learn from giants. Some Open Source Examples:
ETL
StandardCPlusPlus
uClib++
How could I do that? Where should I look for information?
You could check the paper that introduced the feature into the C++ library. For example, std::optional has a stand-alone implementation here which was used as a reference implementation during the proposal stages.
You could check the standard library, and do a laborious study. :-)
Search the internet. :-)
Or write it from scratch as specified by the standard
Will I need to follow exactly what the standard say or I can write a non-compliant version?
There's is no compulsion to follow what the C++ standard library specifies. That would be your "own" library.
Formally, no. As with all standards out there, C++ Standard sets the rules, and does not gives implementation. However, from the practical standpoint, it is nearly impossible to introduce a new feature into Standard Library without proposed implementation, so you often can find those attached to proposals.
As for your questions on "can you write non-compliant version", you can do whatever you want. Adoption might depend on your compliance, or might not - a super-widely adopted MSVC is known to violate C++ standard.
Typically, a new feature is not standardized, unless the committee has some solid evidence that it can be implemented, and will be useful. This very often consists of a prototype implementation in boost, a GNU library, or one of the commercial compiler vendors.
The standard itself does not contain any implementation guidance - it is purely a specification. The compiler vendors (or their subcontractors) choose how to implement that specification.
In the specific case of unique_ptr, it was adopted into the standard from boost::unique_ptr - and you can still use the latter. If you have a compiler that will compile for your microcontroller, it is almost certain that it will be able to build enough of boost to make unique_ptr work.
There is nothing stopping you from writing a non-conforming implementation (apart from the trivial point that if you sold it as being standards-conforming, and it wasn't you might get your local equivalent of Trading Standards come knocking.)
The committee does not release any reference implementations. In the early days, things got standardized and then the tool developers went away and implemented the standard. This has changed, and now the committee looks for features that have been implemented and tested before standardization.
Also major developments usually don't go directly into the standard. First they become experimental features called a Technical Specification or TS. These TS may then be incorporated into the main standard at a later date.
You are free to write you own implementation of the C++ standard library. Plum Hall has a test suite (commercial, I have no connection, but Plum Hall are very involved with C++ standardization).
I don't see any issue with not being conformant. Almost all implementations have some extensions. Just don't make any false claims, especially if you want to sell your product.
If you're interested in getting involved, this can be done via your 'National Body' (ANSI for the USA, BSI for the UK etc.). The isocpp web site has a section on standardization which would be a good starting place.
As highlighted by a recent answer to this question, gcc now supports concepts-lite in builds from its svn trunk.
The same question links to the most recent TS, N4377. Edit - answer has a newer TS.
A helpful paper can be found labelled N3580 - this is from 2013, and the authors are Andrew Sutton, Bjarne Stroustrup and Gabriel Dos Reis.
A list of tweaks to N4377 can be found labelled N4434. This gives 3 suggested changes to the N4377 paper and lists as its reply point Walter E. Brown.
These papers/Technical Specifications are similar, but have various small changes in each case.
Is there some simple way to discover what gcc currently implements? Or indeed, plans to implement?
As a side question: Is ConceptClang or some similarly named project related to the c++1z concepts? A mailing list post from May 2015 collected some thoughts, in particular that:
Larisse may have some work done for the concepts ts, in addition to
her C++0x efforts.
No further reply was made to that thread.
It's my understanding that the GCC maintainers plan to implement Concepts as specified in the final TS that is soon to be published: N4549 C++ Extensions for Concepts. Most of that specification is implemented in GCC, with the notable exception of "generalized auto deduction" which is necessary to compile syntax like std::pair<auto, auto> foo = std::make_pair(x, y);. The implementation is still very rough - a quick search for open bugs with "[concepts]" in the title has 38 hits, so exactly what is implemented and what works well changes from week to week.
Is ConceptClang or some similarly named project related to the c++1z concepts?
ConceptClang is (was?) an implementation of C++0x concepts which I believe has been dead for some time now. There are a few people who have started looking at implementing the Concepts TS in clang in the last several months, they've only submitted a handful of patches to recognize the concept keyword and parse the syntax of concept function and variable declarations.
'Concepts lite' were already accepted as a TS and (example implementation) merged into GCC main branch, so the follow up question is will any concepts come predefined (like Sortable or Random_access_range)?
Where do I look for such predefined concepts?
Is the list at cppreference.com an acurate and exhaustive list?
Can I use them with the latest GCC trunk build?
Edit 1: Changed C++17 to TS due to concepts not being accepted into C++17.
There are no concepts defined in the Concepts TS (source: I wrote the Concepts TS).
It is neither an oversight nor mistake... The goal was to ship a pure language extension in the TS, allowing developers time to experiment with the new features before committing (an incredible amount of) time defining the concepts needed for the Standard Library.
The Ranges TS will define the concepts needed for the Standard Library.
GCC may ship with some concepts, but I have not heard of any concrete plans to do so. I have a library that defines many of the concepts (but not all) that appear in the Ranges TS here: https://github.com/asutton/origin, but I'm still working on a usable release and appropriate documentation. And it only compiles against GCC from trunk. I'm hoping for adequate documentation by next week.
'Concepts lite' were already accepted for C++17
No, it isn't. It's a separate TS.
will any concepts come predefined?
Not by the Concepts TS, which is limited to the language feature. The current Ranges TS working draft does define a number of concepts.
Herb Sutter writes here (on his ISO C++ Spring 2013 meeting trip report) that a networking library is planned to be added to C++14.
What features would this library have initially? What is it based on? Is there a proof-of-concept implementation? My Google-fu must be seriously lacking, because I can't even find the proposal draft.
There are a series of blog posts on http://meetingcpp.com/ listing the proposals for C++14: part 1, part 2, part 3 and part 4. Among all these, I can only find two network-related proposals:
N3555 - a URI Library for C++ (sorry, no link; though its predecessor is N3507.)
N3603 - A Three-Class IP Address proposal (with a related earlier paper N3565 - IP Address Design Constraints.)
Is this all? Will the C++ network library have only these facilities? I don't even know whether these passed the vote or not, as Michael Wong's two part review of the same meeting (Bristol, April 2013) doesn't even mention them.
a networking library is planned to be added to C++14.
A networking library (or set of library components) will appear as a separate Technical Specification, not as part of C++14.
I can only find two network-related proposals
The blog posts don't list all the proposals in the mailings, just the ones someone has found time to write up, there are others such as:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3360.pdf
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3374.htm
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3388.pdf
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3389.pdf
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3565.pdf
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3620.pdf
What will be part of the TS isn't decided yet AFAIK.
I am very interested in seeing the very first implementation of C++ Standard Template Library. Well, it is for historical reasons. I am curious to see how the library evolved throughout the time.
What is the first version (implementation) of STL that is officially available? When and where it was published? How can I get it?
You can follow along with the development of Stepanov's thinking on generic programming at the site he's set up to collect his papers:
http://www.stepanovpapers.com/