Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for a snapshot of the develop branch, built from commit 36319504d5.


template<template<class...> class Op, class... Args>
using is_detected = see-below;

template<template<class...> class Op, class... Args>
constexpr bool is_detected_v = is_detected<Op, Args...>::value;

Aliases: If Op<Args...> is a valid template-id, aliases true_type, otherwise aliases false_type.

C++ Standard Paper: N4502

Compiler Compatibility: Requires C++11 variadic templates and C++11 template aliases.

Header: #include <boost/type_traits/is_detected.hpp>


Suppose we wish to "reset" a value of type T, if the type has a clear() member function then we should call it, otherwise we should assign a default constructed value:

template<class T>
using clear_t = decltype(boost::declval<T&>().clear());

template<class T>
void clear(T& value)
    if constexpr (boost::is_detected_v<clear_t, T>) {
    } else {
        value = T();

See also: is_detected_convertible, is_detected_exact.