Boost logo

Boost :

Subject: [boost] How to detect if f() returns void or not?
From: Frédéric Bron (frederic.bron_at_[hidden])
Date: 2009-12-12 08:38:54


I would like to detect if the return type of a function is void or not
within C++03 standard?
I need that to implement new type traits to detect if types can be
compared and to detect for example operator< returning void.
The following code compiles only with c++0x standard and keyword
decltype but not with c++03 standard and BOOST_TYPEOF.
Frédéric

#include <iostream>
#include <boost/type_traits/is_void.hpp>
#include <boost/typeof/typeof.hpp>

void returns_void();
int returns_int();

int main() {
        std::cout<<std::boolalpha;
// std::cout<<boost::is_void< BOOST_TYPEOF(returns_void()) >::value<<'\n';
// std::cout<<boost::is_void< BOOST_TYPEOF(returns_int()) >::value<<'\n';
        std::cout<<boost::is_void< decltype(returns_void()) >::value<<'\n';
        std::cout<<boost::is_void< decltype(returns_int()) >::value<<'\n';
        return 0;
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk