types: add a 'has_native' trait
Returns true if 'ValueT::native ()' is available.
This commit is contained in:
parent
6dadff769e
commit
f381c24f29
35
types.hpp
35
types.hpp
@ -3,11 +3,10 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/.
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
*
|
*
|
||||||
* Copyright 2011-2014 Danny Robson <danny@nerdcruft.net>
|
* Copyright 2011-2019 Danny Robson <danny@nerdcruft.net>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef CRUFT_UTIL_TYPES_HPP
|
#pragma once
|
||||||
#define CRUFT_UTIL_TYPES_HPP
|
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
@ -96,6 +95,32 @@ namespace cruft {
|
|||||||
|
|
||||||
return sizeof... (t);
|
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 <typename ValueT, typename = std::void_t<>>
|
||||||
|
struct has_native : public std::false_type
|
||||||
|
{};
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
template <
|
||||||
|
typename ValueT
|
||||||
|
> struct has_native<
|
||||||
|
ValueT,
|
||||||
|
std::void_t<
|
||||||
|
decltype(std::declval<ValueT> ().native ())
|
||||||
|
>
|
||||||
|
> : public std::true_type {};
|
||||||
|
|
||||||
|
|
||||||
|
//-------------------------------------------------------------------------
|
||||||
|
template <typename ValueT>
|
||||||
|
constexpr auto has_native_v = has_native<ValueT>::value;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user