In the C++ 11 standard introduced a small collection of utilities for
compile-time introspection and metaprogramming, by way of the type_traits
header. This header was subsequently expanded in the C++14 and C++17 standards.
These facilities are often very helpful in the context of generic programming, namely to dispatch between available templated implementations based on one or more template parameters without resorting to explicit template specialization.
For more information on the standard facilities and this mechanism of template dispatch (i.e. concept emulation), please see the additional resources below.
This library provides:
- backports of
type_typesfeatures introduced within the C++17 standard to C++14 - an extended set of type traits found to be useful in the course of developing other shacl library.
Backports of standard library features are available in the shacl::trait
namespace, albeit under slightly different names in some cases.
std::conjunction->shacl::trait::Conjunctionstd::conjunction_v->shacl::trait::Conjunction_vstd::disjunction->shacl::trait::Disjunctionstd::disjunction_v->shacl::trait::Disjunction_vstd::invoke_result->shacl::trait::InvokeResultstd::invoke_result_t->shacl::trait::InvokeResult_tstd::is_invocable->shacl::trait::InvokeDefinedstd::is_invocable_v->shacl::trait::InvokeDefined_vstd::is_nothrow_invocable->shacl::trait::InvokeNoThrow*std::is_nothrow_invocable_v->shacl::trait::InvokeNoThrow_v*std::is_nothrow_swappable->shacl::trait::SwapNoThrow*std::is_nothrow_swappable_v->shacl::trait::SwapNoThrow_v*std::is_swappable->shacl::trait::Swappablestd::is_swappable_v->shacl::trait::Swappable_vstd::negate->shacl::trait::Negatestd::negate_v->shacl::trait::Negate_vstd::void_t->shacl::trait::void_t
* These shacl traits have slightly different semantics than their standard
library conterparts. In each case, the shacl version of each type trait struct
only has a nested static value data member if (and only if) the prefix trait
is true, whereas the standard library version will always provide a static
value data member. For example, an instantiation of InvokeNoThrow,
parameterized on som type T, will only ha a static value data member iff
shacl::trait::InvokeDefined<T>::value is true.
In addition to the standard library facilities, this library provides additional functionality. For those familiar with the standard library traits, the use these templates should come quite naturally.
shacl::trait::EqualityDefinedandshacl::trait::EqualityDefined_vshacl::trait::EqualityResultandshacl::trait::EqualityResult_tshacl::trait::InequalityDefinedandshacl::trait::InequalityDefined_vshacl::trait::InequalityResultandshacl::trait::InequalityResult_tshacl::trait::EqualityComparableandshacl::trait::EqualityComparable_v
shacl::trait::LessThanDefinedandshacl::trait::LessThanDefined_vshacl::trait::LessThanResultandshacl::trait::LessThanResult_tshacl::trait::LessThanEqualDefinedandshacl::trait::LessThanEqualDefined_vshacl::trait::LessThanEqualResultandshacl::trait::LessThanEqualResult_tshacl::trait::GreaterThanDefinedandshacl::trait::GreaterThanDefined_vshacl::trait::GreaterThanResultandshacl::trait::GreaterThanResult_tshacl::trait::GreaterThanEqualDefinedandshacl::trait::GreaterThanEqualDefined_vshacl::trait::GreaterThanEqualResultandshacl::trait::GreaterThanEqualResult_tshacl::trait::Comparableandshacl::trait::Comparable_v
shacl::trait::MultiplicationDefinedandshacl::trait::MultiplicationDefined_vshacl::trait::Productandshacl::trait::Product_tshacl::trait::DivisionDefinedandshacl::trait::DivisionDefined_vshacl::trait::Quotientandshacl::trait::Quotient_tshacl::trait::Scalableandshacl::trait::Scalable_v
shacl::trait::AdditionDefinedandshacl::trait::AdditionDefined_vshacl::trait::Sumandshacl::trait::Sum_tshacl::trait::SubtractionDefinedandshacl::trait::SubtractionDefined_vshacl::trait::Differenceandshacl::trait::Difference_tshacl::trait::Arithmeticandshacl::trait::Arithmetic_v
shacl::trait::DereferenceDefinedandshacl::trait::DereferenceDefined_vshacl::trait::DereferenceResultandshacl::trait::DereferenceResult_t
shacl::trait::SubscriptDefinedandshacl::trait::SubscriptDefined_vshacl::trait::SubscriptResultandshacl::trait::SubscriptResult_t
shacl::trait::IsRangeandshacl::trait::IsRange_vshacl::trait::RangeTraits
shacl::trait::Identityandshacl::trait::Identity_tshacl::trait::ConditionalApplicationandshacl::trait::ConditionalApplication_t
shacl::trait::Compoundandshacl::trait::Compond_t
As a header-only library, shacl::trait has no compiled components.
Nevertheless, a CMake build system is provided to
allow easy testing, installation, and subproject composition on many platforms
and operating systems. CMake version 3.8 or later is required to configure and
build this library.
The shacl::trait library is written in C++14, and makes considerable use of template metaprogramming and SFINAE. As such, a relatively robust C++ compiler supporting the C++14 standard is required. The following compilers are explicitly supported.
- GNU g++ version 6.0.0 or later
- LLVM clang++ version 3.5 or later
- Xcode version 6.3/Apple clang++ version 9.0.0 or later
- Visual Studio 2017 Update 8 (version 15.8) or later
- Intel icpc version 18.0.3 or later
The current IBM XLC++ compiler (16.1.1) supports only a subset of the C++ 14 standard. It's currently untested with this library.
While the library itself depends only upon the C++ standard library,
testing distributed with the shacl::trait library is dependent on the Catch2
unit testing framework. See the Testing section below for more information.
Given an internet connection, by default, the Catch2 library will be
downloaded (without any need for user intervention) during the CMake
configuration step. If this behavior is undesirable, users can opt to consume a
local installation of Catch2 by setting the git.submodule.packages CMake
option to OFF. Non-standard installation roots to Catch2 can be specified
using the CMAKE_PREFIX_PATH environment variable or CMake option. See the
CMake find_package
documentation for more information. Alternatively, the Catch2 dependency can
be avoided by disabling testing. This can be achieved by setting either the
BUILD_TESTING or trait.tests CMake cache variables to OFF.
The shacl::trait library is distributed with a suite of tests. When
shacl::trait is configured as the highest level CMake project, this suite
of executables is built by default. These test executables are integrated with
the CMake test driver program,
CTest.
CMake supports a number of backends for compilation and linking.
To use a static configuration build tool, such as GNU Make or Ninja:
cd <shacl::trait source directory>
mkdir build
cd build
# Configure the build
cmake -D CMAKE_BUILD_TYPE=<Debug | Release> \
-G <"Unix Makefiles" | "Ninja"> ..
# build the tests
< make | ninja | cmake --build . >
# run the tests
< make test | ninja test | cmake --build . --target test | ctest >To use a dynamic configuration build tool, such as Visual Studio or Xcode:
cd <shacl::trait source directory>
mkdir build
cd build
# Configure the build
cmake -G <"Visual Studio 14 2015 Win64" | "Xcode"> ..
# build the tests
cmake --build . --config <Debug | Release>
# run the tests via ctest...
ctest --build-config <Debug | Release>
# ... or via CMake build tool mode...
cmake --build . --config <Debug | Release> --target testOf course the build and test steps can also be executed via the all and test targets, respectively, from within the IDE after opening the project file generated during the configuration step.
This testing is also configured to operate as a client to the CDash software quality dashboard application. Please see the Kitware documentation for more information on this mode of operation.
The shacl::trait library build system provides an installation target and
support for downstream consumption via CMake's
find_package
intrinsic function. CMake allows installation to an arbitrary location, which
may be specified by defining CMAKE_INSTALL_PREFIX at configure time.
In the absense of a user specification, CMake will install shacl::trait to
conventional location based on the platform operating system.
To use a static configuration build tool, such as GNU Make or Ninja:
cd <shacl::trait source directory>
mkdir build
cd build
# Configure the build
cmake [-D CMAKE_INSTALL_PREFIX="path/to/installation"] \
[-D BUILD_TESTING=False] \
[-D BOOST_ROOT="path/to/boost/installation"] \
-D CMAKE_BUILD_TYPE=Release \
-G <"Unix Makefiles" | "Ninja"> ..
# install shacl::trait
<make install | ninja install | cmake --build . --target install>To use a dynamic configuration build tool, such as Visual Studio or Xcode:
cd <shacl::trait source directory>
mkdir build
cd build
# Configure the project
cmake [-D CMAKE_INSTALL_PREFIX="path/to/installation"] \
[-D BUILD_TESTING=False] \
[-D BOOST_ROOT="path/to/boost/installation"] \
-G <"Visual Studio 14 2015 Win64" | "Xcode"> ..
# install shacl::trait
cmake --build . --config Release --target installNote that the last command of the installation sequence may require
administrator privileges (e.g. sudo) if the installation root directory lies
outside your home directory.
This installation
- copies the shacl::trait header files to the
include/shaclsubdirectory of the installation root - generates and copies several CMake configuration files to the
share/cmake/shacl/traitsubdirectory of the installation root
This latter step allows downstream CMake projects to consume shacl::trait via
find_package, e.g.
find_package(shacl REQUIRED COMPONENTS trait)
target_link_libraries(MyTarget PUBLIC shacl::trait)If shacl::trait was installed to a non-conventional location, it may be
necessary for downstream projects to specify the shacl installation root
directory via either
- the
CMAKE_PREFIX_PATHconfiguration option, - the
CMAKE_PREFIX_PATHenvironment variable, or shacl_DIRenvironment variable.
Please see the Kitware documentation for more information.
In addition, shacl::trait supports packaged relocatable installations via CPack. Following configuration, from the build directory, invoke cpack as follows to generate a packaged installation:
cpack -G <generator name> -C ReleaseThe list of supported generators varies from platform to platform. See the
output of cpack --help for a complete list of supported generators on your
platform.
See license file.
In suggested order