How to (and who can) implement the standard library features defined by the C++ committee?

泪湿孤枕 提交于 2021-02-07 06:54:10

问题


When the C++ committee publish a new feature that will be part of the standard library in the next standard of the language, 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 this process of implementation of the standard library features occurs.

Can anyone implement parts of the standard library for a platform that doesn't have support for it 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 turn my project open source, can I do that? Will I need to follow exactly what the standard say or I can write a non-compliant version?


回答1:


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.




回答2:


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.




回答3:


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.)




回答4:


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.



来源:https://stackoverflow.com/questions/45194205/how-to-and-who-can-implement-the-standard-library-features-defined-by-the-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!