Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++14, C++17 and forward #52

Closed
15 of 23 tasks
mosra opened this issue May 4, 2014 · 5 comments
Closed
15 of 23 tasks

C++14, C++17 and forward #52

mosra opened this issue May 4, 2014 · 5 comments

Comments

@mosra
Copy link
Owner

mosra commented May 4, 2014

This used to be a list of exciting new features present in newer C++ standards to look forward to. Now it's rather a list of non-insance C++14+ features that could be worth backporting to C++11.

C++14

  • Support in the CORRADE_CXX_STANDARD CMake property and preprocessor macro
  • Exposing C++14 constexpr via CORRADE_CONSTEXPR14 -- mosra/corrade@9cf91f0
  • Backport std::integer_sequence optimizations -- mosra/corrade@0b82814
  • Make use of sized deallocation
    • All array deleters are already prepared for this, as they get the length as well

Compiler support

  • GCC 4.9 (released on April 22 2014) is probably the first GCC with considerable chunk of C++14 features implemented (4.8 not so much)
  • Clang 3.4 has full C++14 support (on the other hand, 3.3 has nearly nothing from it)
  • MSVC 2015 (?) -- they implement both C++11 and C++14 simultaneously with varying success, so let's hope it is supported well enough in the next release

For all compilers we need to wait until their usage is similar to GCC 4.7 and Clang 3.2 just now (May 2014). We'll see after dropping GCC 4.7 support (#274).

Good resources about compiler support are at http://www.g-truc.net/project-0036.html for major vendors and also at http://en.cppreference.com/w/cpp/compiler_support for the other.

Features

  • relaxed constexpr -- it would be finally possible to implement compile-time MurmurHash without the code being write-only, also many math functions will benefit from that (so the user doesn't need to precompute math operations in tight loops by hand, but can just slap constexpr specifier on the result and be done with it). Experimental stuff already available in cpp14 branch.
  • variable templates (i.e. Pi<float>) -- not sure about the usage, the current way with enums and functions ensures that the value is not exposed as any linkable symbol (you can't take address of enum or function result), which in my opinion is exactly what we want for constants -- to be always on stack and not referenced through some slow indirection. Also this (from API perspective) is easily doable using template aliases, am I missing something?
  • binary literals -- probably not so useful in library code, as for flags 1 << n is much more readable
  • digit separators -- also rather in user code than in library code
  • [[deprecated]] attribute might help with getting rid of the ugly CORRADE_DEPRECATED() macro and its compiler-specific quirks actually no, the attribute can be used for enums and namespaces only since C++17, so the macro is going to stay
  • make use of feature test macros for C++14+ features instead of relying on STL/compiler version checks hahahah you wish, as long as compilers are buggy this is only a wet dream

STL features

The issue is that these won't be advertised in compiler release changelogs and thus we might have some very nasty surprises (e.g. std::map::emplace() didn't exist until GCC 4.8).

  • std::float32_t and std::float64_t instead of float and double, just to be consistent with strict type definitions we already have for integers this proposal disappeared somehow
  • std::enable_if_t<...> instead of typename std::enable_if<...>::type (and similar) -- 13 characters shorter, will help a lot in implementation details of generic classes not worth the backwards compatibility pain
  • std::make_unique() for much less verbose std::unique_ptr construction nope, making my own thing
  • std::exchange() utility function instead of the following fugly piece of code -- could also implement my own, and wasn't all that essential after all
  • std::string literals, I hope they help with avoiding the copy and allocation on construction, otherwise I can't think of any other use case (apart from proper '\0' handling) no, they don't, gah; having my own StringView (and string literals) nowadays

C++17

Compiler support

  • MSVC 2015 Update 4+, Clang 3.8+, GCC 6+?

Features

  • template argument deduction for class templates -- obsoletes all make*() helpers -- thanks to our naming scheme, the "make" helpers are not any longer than using the class name directly (pointer() vs Pointer), so this is a non-issue
  • static_assert() without message -- useful for user code, not library code, there we should provide a message always

STL features

  • std::observer_ptr instead of raw pointers sorry, bad joke
  • std::is_integral_v<...> instead of std::is_integral<...>::value (and similar) - 5 characters shorter (slower compile times?) not worth the backwards compatibility pain
  • std::void_t (N3911) has an interesting example to simplify CORRADE_HAS_TYPE() macro
  • constructing std::tuple with just {} -- I basically banned std::tuple from the codebase since
  • uninitialized_value_construct() etc. as more optimal alternatives to placement-new-in-a-loop in Containers::Array NoInit and other versions (but one needs <memory> for that, ugh)
  • finally a crossplatform filesystem handling to replace our own incompletely tested Corrade::Utility::Directory I doubt it will ever catch up with my requirements, also there's a very small intersection between what I need (isSandboxed()) vs what it provides (operator/ for concatenating directories, wtf)

C++20

Features

STL features

C++23

Features

  • #elifdef / #elifndef; I wonder when it will make sense to upgrade to C++23 just to get these (or maybe they'll be usable even wiithout picking the full standard?)
  • operator[] where I can use ,, finally
    • Implement that in StridedArrayView, and an operator() fallback until then
    • Implement that in Matrix, and an operator() fallback until then

STL features

Not yet

  • Compatibility of StridedArrayView with std::mdspan
  • variable-length arrays, which will avoid heap allocations in some cases. Main use case is converting std::initializer_list<T> parameters to GLuint[] when passing them to glBindTextures(), glShaderSource() and other "multi" functions. Not part of C++14, but available in GCC since forever as GNU extension and it is made "official" in 4.9. Clang originally chose to not implement this at all, so it's not available in it yet. On the other hand, if I'm lucky I might be able to work around the allocation with some implicit conversions and then pass the std::initializer_list data directly. too slow, error prone and dangerous, won't use that ever (case in point: Linux kernel removed them all for better stability)
  • std::vector::release() and an "acquire" counterpart -- rejected from C++17, nobody cared since then, and I have switched to my own containers anyway
@waddlesplash
Copy link

MSVC 2014 (?) -- they implement both C++11 and C++14 simultaneously with varying success, so let's hope it is supported well enough in the next release

From experience with working with MSVC 2013, the C++11 support they added (at least std::thread & std::unique_ptr) was OK, but it took a few patch releases to get it fully working. So there's that added delay too...

@mosra mosra changed the title C++14 / C++1y C++14, C++17 and forward Oct 16, 2016
@TheAifam5
Copy link

TheAifam5 commented Jul 19, 2018

Hmm what about to move everything to Clang (not GCC or MSVC) ? They are doing really good work, also with support for Windows platform: https://clang.llvm.org/docs/MSVCCompatibility.html
Also on Linux there are tests to compile the Linux kernel with Clang compiler, Debian tries to re-compile all packages, Android uses also Clang (android/ndk#26)...

Also MSVC installer actually have an option to install Clang with it (old version 6.0 i think).

I think, just wait only 5 months or 1 year and Clang will take over the MSVC compiler (I seen tweets that Clang actually started destroying MSVC compiler - they just moved from it) :D

I'm talking here about MSVC because is the most problematic platform. On Linux and Mac users can use Clang without any problems, but on Windows only MSVC or Cygwin-like stuff.

@mosra
Copy link
Owner Author

mosra commented Jul 20, 2018

There are embedded Linux platforms that don't have the option to use Clang instead of GCC and I have important clients on these -- can't just drop GCC support :) Besides that, at the moment it's possible to just use a stock Ubuntu with whatever GCC is installed on it and that's a nice "plug and play" feature I wouldn't want to lose.

I'll introduce support for C++14 and 17 features on an opt-in basis (for example enabling constexpr for more APIs) -- if you enable the C++14/17 standard via a compiler switch, they'll be there, otherwise not. To avoid maintenance nightmares, these will affect mainly the public-facing API, the internal code will stay on C++11 as long as it's feasible.

@mosra mosra pinned this issue Feb 12, 2019
@mosra mosra unpinned this issue Feb 18, 2020
@ttnghia
Copy link
Contributor

ttnghia commented Jan 6, 2021

@mosra C++20 mentioned, yeah 😛

@mosra
Copy link
Owner Author

mosra commented Oct 4, 2024

Closing as most of the checklist above is implemented. The remaining bits are tracked in various project cards, in particular the Corrade / Containers project, features from newer C++ standards are going to be added on an as-needed / as-requested basis.

@mosra mosra closed this as completed Oct 4, 2024
@github-project-automation github-project-automation bot moved this from In progress to Done in Magnum / Project management Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

4 participants