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

use feature test macros instead of version checks #623

Conversation

benedekkupper
Copy link
Contributor

@benedekkupper benedekkupper commented Oct 15, 2022

I have started working on #572 myself, the branch is currently work in progress, so don't consider this a real PR at the moment, more of an indication that there's something being done in this direction.

My workflow is this:

  1. git grep ETL_USING_CPP
  2. Try to deduct what feature is needed from that version of C++.
  3. Look up the macro name for the feature on https://en.cppreference.com/w/cpp/feature_test
  4. If found, replace ETL_USING_CPPxx with the feature test macro, otherwise add a comment to determine_compiler_language_support.h

@benedekkupper benedekkupper changed the title use feature test macros instead of version checks (# use feature test macros instead of version checks Oct 16, 2022
@benedekkupper benedekkupper marked this pull request as ready for review October 16, 2022 21:51
@jwellbelove
Copy link
Contributor

jwellbelove commented Oct 17, 2022

I'm not sure how these can be used before C++20.
e.g.
How can you use C++20's __cpp_rvalue_references in place of ETL_USING_CPP11?
In a compiler only supporting, C++11 __cpp_rvalue_references will be undefined.

@jwellbelove
Copy link
Contributor

As your link mentions, these feature test macros are only defined for compilers that support C++20 or above.

Feature testing (since C++20) <<<<<<
Feature testing
The standard defines a set of preprocessor macros corresponding to C++ language and library features introduced in C++11 or later. They are intended as a simple and portable way to detect the presence of said features.

@benedekkupper
Copy link
Contributor Author

I have backported these feature test macros into determine_compiler_language_support.h, see ETL_NO_STD_FEATURE_TESTS section. There is a <version> header defined in C++20 that only contains these macros, hopefully the compilers that add support for this in their C++20 version, also add this header to their earlier version lib as well. Even if not, I have added the macros that are used by ETL (also some notes on what macros are missing, etc).

Using these macros gives a better idea on what compiler features are required, and possibly extend the compiler support in case a compiler version only implements a subset of a C++ version (e.g. the current arm gcc C++20 version is missing a bunch of C++20 functionality, so just checking for the C++ version enables code sections that don't actually have compiler support yet.

@jwellbelove jwellbelove changed the base branch from master to feature/#623-use-feature-test-macros-instead-of-version-checks October 19, 2022 10:58
@jwellbelove jwellbelove deleted the branch ETLCPP:feature/#623-use-feature-test-macros-instead-of-version-checks October 19, 2022 11:04
@jwellbelove jwellbelove reopened this Oct 19, 2022
@jwellbelove jwellbelove merged commit 8196254 into ETLCPP:feature/#623-use-feature-test-macros-instead-of-version-checks Oct 19, 2022
@benedekkupper benedekkupper deleted the feature-test-macros branch October 21, 2022 22:05
jwellbelove added a commit that referenced this pull request Dec 14, 2022
* Update README.md

* Update README.md

* use feature test macros instead of version checks

Co-authored-by: John Wellbelove <jwellbelove@users.noreply.github.com>
jwellbelove added a commit that referenced this pull request Dec 14, 2022
…-checks' of https://github.com/ETLCPP/etl into feature/#623-use-feature-test-macros-instead-of-version-checks

# Conflicts:
#	include/etl/utility.h
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

2 participants