Skip to content

Nandite/bazaar_traits

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Bazaar traits

This project is a standalone implementation of the C++ metaprogramming library using C++17. Following years of learning about template metaprogramming and type traits, I came to the conclusion that the best way of understanding the field was extensive practice. It is one of the easiest way to get up to speed on writing compile time algorithms and meta-functions. So a quick way to exercise was to implement the metaprogramming library from ground.

Unlike most of the implementation (GCC, LLVM etc.), the meta-functions in this project are divided into multiple files under the include directory with bases traits in their own files (helper traits, Integral constant, logical operators...). The bulk of the meta-functions implementation however are inside the bazaar_traits file.

A synopsis file containing the list of all implemented (and to be implemented) traits is also available.

Usage

This repository is a standalone CMake project. You can open it with any IDE supporting CMakeLists. You can then compile the test target. Using a sufficiently modern IDE, you can take a look of the test files and get in live the results of the meta-functions calls.

Depending on your compiler, you can get different results. Indeed, some traits require attributes that are only visible by the compiler and thus need compiler support to be implemented. There is a good listing and explanation about which meta-function need compiler support and why at this page. When compiler support is not mandatory and not available, there are fallbacks on internal implementations of the traits that try to stick at most to the C++ specifications. Otherwise, a shallow implementation is used or in certain case the result is literally deactivated using false_type (equivalent to systematically return false at function calls).

This implementation has been tested using the following compilers:

  • gcc 9.4.0
  • Clang 10
  • Clang 14

Caution

Please, do not use the code of this project into production. Use instead the facilities provided through the standard library of your C++ compiler. This repository is first and foremost for learning purposes.

CppCon talks

If you want to learn about metaprogramming, i advice watching the CppCon talks of Walter E. Brown and Jody Hagins about the subject:

These talks require a good knowledge of C++ and template programming. They are not intended for beginners.

Feedback

Don't hesitate if you have any suggestions for improving this project, or if you find any error. I will be glad to hear from you. There are traits that have been implemented yet. You can submit implementations suggestions. Contributions are welcomed :)

License

Distributed under the MIT Software License (X11 license). See accompanying file LICENSE.