Commit Graph

3 Commits

Author SHA1 Message Date
David P. Sicilia a5d9d0f7d3 [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.
2020-01-02 10:12:14 -08:00
Austin Schuh 901b89e733 [C++] Add Builder and Table typedefs (#5685)
* Add Builder and Table typedefs

This gives us a way to use templates to go from a builder to a table
and back again without having to pass both types in.

* Fix tests/cpp17/generated_cpp17/monster_test_generated.h
2019-12-26 14:56:46 -08:00
Vladimir Glavnyy 44bf719883 Add flatc '--cpp_std' switch (#5656)
* Add flatc '--cpp_std' switch and sandbox for C++17 code generator

- Added 'flac --cpp_std legacy' for compatibility with old compilers (VS2010);
- Added experimental switch 'flac --cpp_std c++17' for future development;
- Added C++17 sandbox test_cpp17.cpp;
- C++ code generator generates enums with explicit underlying type to avoid problems with the forward and backward schema compatibility;
- Adjusted CMakeLists.txt, CI and generate code scripts to support of introduced '--cpp_std';

* Fix --cpp_std values: c++0x, c++11, c++17

* Add 'cpp::CppStandard' enum

* Add testing engine into test_cpp17

* Rebase to upstream/master

* Set default '--cpp-std C++0x'

* Fix code generation (--cpp_std C++11) in CMakeLists.txt

- Fix dependency declaration of grpctest target

* Revert --cpp-std for the tests from explicit C++11 to flatc default value (C++0x)
2019-12-23 12:13:48 -08:00