From f381c24f29f27e3fd6893addefa3e835956b7e7a Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Wed, 27 Feb 2019 11:14:45 +1100 Subject: [PATCH] types: add a 'has_native' trait Returns true if 'ValueT::native ()' is available. --- types.hpp | 35 ++++++++++++++++++++++++++++++----- 1 file changed, 30 insertions(+), 5 deletions(-) diff --git a/types.hpp b/types.hpp index 37581cf7..31ce63bf 100644 --- a/types.hpp +++ b/types.hpp @@ -3,11 +3,10 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * - * Copyright 2011-2014 Danny Robson + * Copyright 2011-2019 Danny Robson */ -#ifndef CRUFT_UTIL_TYPES_HPP -#define CRUFT_UTIL_TYPES_HPP +#pragma once #include #include @@ -96,6 +95,32 @@ namespace cruft { return sizeof... (t); } -} -#endif + + + /////////////////////////////////////////////////////////////////////////// + /// A trait that tests for the presence of a 'native' member function. + /// + /// Not terrifically useful by itself, but it is use reasonably frequently + /// in various library wrappers that we maintain (to return the underlying + /// native objects). + template > + struct has_native : public std::false_type + {}; + + + //------------------------------------------------------------------------- + template < + typename ValueT + > struct has_native< + ValueT, + std::void_t< + decltype(std::declval ().native ()) + > + > : public std::true_type {}; + + + //------------------------------------------------------------------------- + template + constexpr auto has_native_v = has_native::value; +}