diff options
author | David P. Sicilia <dpacbach@users.noreply.github.com> | 2020-01-02 13:12:14 -0500 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2020-01-02 10:12:14 -0800 |
commit | a5d9d0f7d368054fd1691aedf1db4116efcc233e (patch) | |
tree | 8d252e4ad24f5cd6331f70a09aa1dcad166037da /CMakeLists.txt | |
parent | 3cd9b6434a6f4ec5ee6c49d1b9fd58209d714e82 (diff) | |
download | flatbuffers-a5d9d0f7d368054fd1691aedf1db4116efcc233e.tar.gz flatbuffers-a5d9d0f7d368054fd1691aedf1db4116efcc233e.tar.bz2 flatbuffers-a5d9d0f7d368054fd1691aedf1db4116efcc233e.zip |
[C++17] Add Traits class for Tables and Factory function within it. (#5678)
* Include flattests_cpp17 in unit tests when C++17 build is enabled.
* [C++17] Generate generic table factory function.
1. For each table, generate a convenient free-standing factory
function that allows creating the table in a generic way by
specifying only the type. This is the first change in a series
of changes to make Flatbuffers generated C++ code more friendly
to code bases that make use of C++ template metaprogramming
techniques to manage the serialization process. Example:
Before :(
// The name of the Flatbuffers type (and namespace) must
// be hard-coded when writing the factory function.
auto monster = MyGame::Example::CreateMonster(fbb, ...);
After :)
using type_to_create = MyGame::Example::Monster;
// No namespace needed on CreateByTagType.
auto monster = CreateByTagType((type_to_create*)nullptr,
fbb, ...);
This feature requires building with C++14 or greater, and thus
it is guarded behind --cpp-std >= c++17 in the flatbuffers C++
generator.
2. Fix a CMake bug to include C++17 unit tests in test suite.
* [C++17] Replace standalone variadic factory function with type_traits.
Add a `type_traits` to each table class. This `type_traits` can be
populated with various compile-time info about the table. Initially,
we have the Create* function and type, but is extensible in the future.
* Remove empty line and fix stale comments.
* Rename type_traits to Traits and move fwd declaration.
* Fix parameter evaluation order issue and use lambda for scope.
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r-- | CMakeLists.txt | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d4ecc81..2fed2019 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -530,6 +530,9 @@ if(FLATBUFFERS_BUILD_TESTS) file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") add_test(NAME flattests COMMAND flattests) + if(FLATBUFFERS_BUILD_CPP17) + add_test(NAME flattests_cpp17 COMMAND flattests_cpp17) + endif() if(FLATBUFFERS_BUILD_GRPCTEST) add_test(NAME grpctest COMMAND grpctest) endif() |