Is there a way to use the discovery identifier (or another method) to check if the function is valid for the given template arguments, if that failed due to static_assert?
The example below shows that confidence foo(failure to evaluate return type) is determined by purpose, but not for bar(failure static_assert).
#include <iostream>
#include <type_traits>
template <typename... T> using void_t = void;
template <class AlwaysVoid, template<class...> class Op, class... Args>
struct detector: std::false_type { };
template <template<class...> class Op, class... Args>
struct detector<void_t<Op<Args...>>, Op, Args...>: std::true_type { };
template <template<class...> class Op, class... Args>
constexpr bool is_detected = detector<void, Op, Args...>::value;
template <typename T>
std::enable_if_t<!std::is_void<T>::value> foo() {
std::cout << "foo" << std::endl;
}
template <typename T>
void bar() {
static_assert( !std::is_void<T>::value );
std::cout << "bar" << std::endl;
}
template <typename T> using foo_t = decltype(foo<T>());
template <typename T> using bar_t = decltype(bar<T>());
int main(int argc, char* argv[]) {
foo<int>();
bar<int>();
std::cout << std::boolalpha;
std::cout << is_detected<foo_t,int > << std::endl;
std::cout << is_detected<foo_t,void> << std::endl;
std::cout << is_detected<bar_t,int > << std::endl;
std::cout << is_detected<bar_t,void> << std::endl;
}
It is for this reason that I can not determine whether boost::lexical_castfor the given types.
source
share