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

Remove SFINAE in some places #3

Merged
merged 3 commits into from
Jan 24, 2022

Conversation

franzpoeschel
Copy link

With if constexpr we can now often avoid SFINAE constructs, making code easier to read and faster to compile

  • One instance can be removed in the implementation of switchType
  • The AttributeTypes class in ADIOS2 uses specializations to enable different implementations of attributes based on type. This has always been annoying to read because each function was defined like 10 times.
    Not yet inlined: attributeUnchanged (will do), (new)createAttribute, (new)readAttribute (won't do, these will be removed anyway along with the new schema).
    The AttributeTypes class can then fully be removed.

TODO: Remove SFINAE and similar constructs in other places. Search for enable_if.

@franzpoeschel franzpoeschel changed the base branch from dev to topic-cxx17 January 24, 2022 15:41
@franzpoeschel franzpoeschel force-pushed the topic-cxx17 branch 2 times, most recently from 03631f0 to e1f7d9e Compare January 24, 2022 16:35
@franzpoeschel
Copy link
Author

Occurrences of enable_if:

> grep -R enable_if include/ src
include/openPMD/RecordComponent.hpp:    typename std::enable_if<
include/openPMD/auxiliary/OutOfRangeMsg.hpp:            typename = typename std::enable_if<
include/openPMD/RecordComponent.tpp:inline typename std::enable_if<
include/openPMD/backend/Attribute.hpp:    -> typename std::enable_if< convertible, std::vector< UU > >::type
include/openPMD/backend/Attribute.hpp:    -> typename std::enable_if< !convertible, std::vector< UU > >::type
include/openPMD/backend/Attribute.hpp:    -> typename std::enable_if< convertible, std::vector< UU > >::type
include/openPMD/backend/Attribute.hpp:    -> typename std::enable_if< !convertible, std::vector< UU > >::type
include/openPMD/backend/Attribute.hpp:    -> typename std::enable_if< convertible, std::vector< UU > >::type
include/openPMD/backend/Attribute.hpp:    -> typename std::enable_if< !convertible, std::vector< UU > >::type
include/openPMD/backend/Attribute.hpp:    -> typename std::enable_if< convertible, std::array< UU, n > >::type
include/openPMD/backend/Attribute.hpp:    -> typename std::enable_if< !convertible, std::array< UU, n > >::type
include/openPMD/Mesh.hpp:              typename = std::enable_if_t<std::is_floating_point< T >::value> >
include/openPMD/Mesh.hpp:              typename = std::enable_if_t<std::is_floating_point< T >::value> >
include/openPMD/IO/JSON/JSONIOHandlerImpl.hpp:            typename std::enable_if<
src/IO/JSON/JSONIOHandlerImpl.cpp:        typename std::enable_if<

@@ -898,18 +841,36 @@ namespace detail
}
};

namespace bool_repr
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for now a duplication of the same code inside AttributeTypes< bool >. The latter will be removed as soon as the new ADIOS2 schema is fully removed.

@ax3l ax3l self-requested a review January 24, 2022 16:46
@ax3l ax3l self-assigned this Jan 24, 2022
@ax3l ax3l mentioned this pull request Jan 24, 2022
8 tasks
@ax3l
Copy link
Owner

ax3l commented Jan 24, 2022

@franzpoeschel can you please rebase this?
Had to rebase the main topic-cxx17 branch to make std::optional merge properly.

@ax3l ax3l force-pushed the topic-cxx17-sfinae branch from a00a664 to eb39562 Compare January 24, 2022 17:35
@ax3l ax3l merged commit 8a364f6 into ax3l:topic-cxx17 Jan 24, 2022
ax3l added a commit that referenced this pull request Jan 27, 2022
* Remove: MPark.Variant (internal)

* CMake: C++17

* Docs: w/o MPark.Variant

* Docs: C++17

* Remove C++14-only Code

* Variant/Option: only `std::variant` as source

* CI: Clang 5->6, GCC 5->7

* Clang6: Ubuntu 20.04

The shipped libstd++ (GCC10?) does not seem to work well with Clang 6
on Ubuntu 18.04 - try again on Ubuntu 20.04.

* clang-tidy-10: namespace & nodiscard

C++17 modernizations that it found:
- `modernize-concat-nested-namespaces`
- `modernize-use-nodiscard`

* macOS: raise deployment target to 10.13

```
error: 'visit<(lambda at ...include/openPMD/backend/Attribute.hpp:239:9),
              std::variant<...> &>'
is unavailable: introduced in macOS 10.13
```

`std::filesystem` needs macOS 10.15:
```
share/openPMD/thirdParty/toml11/toml/parser.hpp:2166:65:
error: 'path' is unavailable: introduced in macOS 10.15
basic_value<Comment, Table, Array> parse(const std::filesystem::path& fpath)
                                                                ^
/Applications/Xcode_13.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/filesystem:902:24:
note: 'path' has been explicitly marked unavailable here
class _LIBCPP_TYPE_VIS path {
                       ^
```

* clang6 on Linux: use libc++

Issues with clang 6 on `<variant>` from GCC's libstdc++:
- https://stackoverflow.com/a/46507150/2719194
- https://bugs.llvm.org/show_bug.cgi?id=31852
- https://bugs.llvm.org/show_bug.cgi?id=33222

Using libc++:
- https://libcxx.llvm.org/UsingLibcxx.html

* Add a Clang 7 build

* add libc++abi-dev

* Clang 6: `-Wno-ignored-attributes -Wno-unused-const-variable`

clang-6 has a false positive on `src/auxiliary/Filesystem.cpp`
with `-Wno-ignored-attributes`:
```C++
[[maybe_unused]] MPI_Datatype const MPI_Types< unsigned >::value = MPI_UNSIGNED;
```

Adding only `-Wno-ignored-attributes` then leads to:
```
src/auxiliary/Filesystem.cpp:201:47: error: unused variable 'value' [-Werror,-Wunused-const-variable]
    MPI_Datatype const MPI_Types< unsigned >::value = MPI_UNSIGNED;
                                              ^
```

* README: C++17 Structure Bindings

Modernize "first read" C++ example with structured bindings

* Doc: Support Clang 7+

For `<variant>`, clang 6 is not to be recommended for C++17 compilation
unless by expert users that know how to change the stdlib.

Thus, let's only recommend Clang 7+.

Ubuntu 18.04 (bionic/oldstable) ships clang 6 by default, but
Ubuntu 20.04 (focal/stable) is already at clang 10.

* C++17: Replace auxiliary::Option with std::optional

* Replace auxiliary::Option with std::optional

* Remove SFINAE in some places (#3)

* switchType: avoid SFINAE constructs

* Remove template specializations: oldCreateAttribute, oldReadAttribute

* CI fixes

Co-authored-by: Franz Pöschel <franz.poeschel@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants