src/cpp-common/bt2: add `bt2::AddConst` and `bt2::RemoveConst`
This patch adds the `bt2::AddConst` and `bt2::RemoveConst` structure
templates in `src/cpp-common/bt2/type-traits.hpp` which both provide the
`Type` type alias to transform a const object type into a non-const
object type and vice versa.
For example, `bt2::AddConst<bt2::ClockClass>::Type` is
`bt2::ConstClockClass` and `bt2::RemoveConst<bt2::ConstMapValue>::Type`
is `bt2::MapValue`.
I needed this to call something like
bt2::RemoveConst<typename LibFcT::Mapping::RangeSet>::Type::create()
where `LibFcT` is some non-const enumeration field class, but I decided
to implement it for all the types right now.
Internally, we add something like this for all type pairs:
namespace internal {
struct XyzTypeDescr
{
using Const = ConstXyz;
using NonConst = Xyz;
};
template <>
struct TypeDescr<Xyz> : public XyzTypeDescr
{
};
template <>
struct TypeDescr<ConstXyz> : public XyzTypeDescr
{
};
} /* namespace internal */
The type trait structure templates in `type-traits.hpp` just use
`internal::TypeDescr`, for example:
template <typename ObjT>
struct RemoveConst
{
using Type = typename internal::TypeDescr<ObjT>::NonConst;
};
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Change-Id: Ia4d44a286fd836dcdb2a0f37c5a08a43bad5508e
Reviewed-on: https://review.lttng.org/c/babeltrace/+/8008
Reviewed-on: https://review.lttng.org/c/babeltrace/+/10791
Tested-by: jenkins <jenkins@lttng.org>
This page took 0.025369 seconds and 4 git commands to generate.