Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Return Type Features

return_type
apply_return
has_void_return
Header
#include <boost/callable_traits/return_type.hpp>
Definition
template<typename T>
using return_type_t = //implementation-defined

template<typename T>
struct return_type {
    using type = return_type_t<T>;
};
Constraints
  • T must be one of the following:
    • function
    • function pointer
    • function reference
    • member function pointer
    • member data pointer
    • user-defined type with a non-overloaded operator()
    • type of a non-generic lambda
Behavior
  • When the constraints are violated, a substitution failure occurs.
  • The aliased type is the return type of T.
Compatibility Notes

Full support on GCC 4.7.4+, Clang 3.5+, Visual Studio 2015, and XCode 6.4+.

Input/Output Examples

T

return_type_t<T, std::tuple>

void()

void

float(*)()

float

const char*(&)()

const char *

int(foo::*)() const

int

int

(substitution failure)

int (*const)()

(substitution failure)

Example Program
#include <type_traits>
#include <boost/callable_traits.hpp>

namespace ct = boost::callable_traits;

using expect = int;

struct foo;

template<typename T>
void test() {
    using result = ct::return_type_t<T>;
    static_assert(std::is_same<expect, result>{}, "");
}

int main() {

    test<int()>();
    test<int(*)()>();
    test<int(&)()>();
    test<int() const>();
    test<int(foo::*)() const>();

    auto x = []() -> int { return 0; };

    test<decltype(x)>();
}
Header
#include <boost/callable_traits/apply_return.hpp>
Definition
template<typename T, typename R>
using apply_return_t = //implementation-defined

template<typename T, typename R>
struct apply_return {
    using type = apply_return_t<T, R>;
};
Constraints
  • T must one of the following:
    • std::tuple template instantiation
    • function
    • function pointer
    • function reference
    • member function pointer
    • member data pointer
Behavior
  • When T is std::tuple<Args...>, the aliased type is R(Args...).
  • When T is a function, function pointer, function reference, or member function pointer, the aliased type's return type is R, but is otherwise identical to T.
  • When T is a member data pointer of class foo to a U type (such that T is U foo::*), the aliased type is R foo::*.
Compatibility Notes

Full support on GCC 4.7.4+, Clang 3.5+, Visual Studio 2015, and XCode 6.4+.

Input/Output Examples

T

apply_return_t<T, float>

std::tuple<int, int>

float(int, int)

int()

float()

int (&)()

float(&)()

int (*)()

float(*)()

int (*)(...)

float(*)()

int(foo::*)()

float(foo::*)()

int(foo::*)() &

float(foo::*)() &

int(foo::*)() &&

float(foo::*)() &&

int(foo::*)() const

float(foo::*)() const

int(foo::*)() transaction_safe

float(foo::*)() transaction_safe

int foo::*

float foo::*

int

(substitution failure)

int (*const)()

(substitution failure)

Example Program

[apply_return]

Header
#include <boost/callable_traits/has_void_return.hpp>
Definition
template<typename T>
struct has_void_return; //implementation-defined


#ifdef CALLABLE_TRAITS_DISABLE_VARIABLE_TEMPLATES

template<typename T>
struct has_void_return_v {
    static_assert(sizeof(T) < 1,
        "Variable templates not supported on this compiler.");
};

#else

template<typename T>
constexpr bool has_void_return_v = //implementation-defined
#endif
Constraints
  • none
Behavior
  • std::false_type is inherited by has_void_return<T> and is aliased by typename has_void_return<T>::type, except when one of the following criteria is met, in which case std::true_type would be similarly inherited and aliased:
    • T is a function, function pointer, or function reference where the function's return type is void.
    • T is a pointer to a member function whose return type is void.
    • T is a function object with a non-overloaded operator(), where the operator() function returns void.
  • On compilers that support variable templates, has_void_return_v<T> is equivalent to has_void_return<T>::value.
Compatibility Notes

Full support on GCC 4.7.4+, Clang 3.5+, Visual Studio 2015, and XCode 6.4+.

Input/Output Examples

T

has_void_return_v<T>

void()

true

void(int) const

true

void(*)()

true

void(&)()

true

void(foo::*)() const

true

int(*)()

false

int(*&)()

false

int

false

int foo::*

false

void* foo::*

false

Example Program
#include <type_traits>
#include <boost/callable_traits/has_void_return.hpp>

namespace ct = boost::callable_traits;

static_assert(ct::has_void_return<void()>::value, "");
static_assert(!ct::has_void_return<int()>::value, "");

int main() {}

PrevUpHomeNext