Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
const header_t header = request.header(); const int status = header.statusCode(); const header_t::body_t body = header.responseBody(); // header_t::body_t какая-то структура типа вектора, возможно ref-counting // и хранящая внутри указатель, во избежание копирования const size_t bodyLength = body.size(); // итд
#include <boost/mpl/map.hpp> #include <boost/mpl/at.hpp> #include <boost/mpl/int.hpp> #include <boost/config.hpp> #include <iostream> #include <string> // accessor functions stubs // in these function you will obtain value with HttpQueryInfo by valueCode template< typename ResultT > ResultT get_value( int valueCode ); template< > std::string get_value< std::string >( int valueCode ) { return "hi!"; } template< > int get_value< int >( int valueCode ) { return valueCode * 42; } using namespace boost::mpl; // just for simplify // mpl::map valueCode on result type typedef map< pair< int_< 0 >, int >, pair< int_< 1 >, int >, pair< int_< 2 >, std::string >, pair< int_< 3 >, int > > test1; // helper structure which help us to avoid to use // long - at< test1, int_< i > >::type template< int i > struct toResultType { typedef typename at< test1, int_< i > >::type type; }; // interface function template < int i > typename toResultType< i >::type func() { return get_value< toResultType< i >::type > ( i ); } int main() { std::cout << func<0>() << "\n" << func<1>() << "\n" << func<2>() << "\n" << func<3>() << "\n"; }
mpl::map
pair< int_< 0 >, int >,
я бы все равно заменил на макрос с говорящим названием, чтобы было нагляднее тому, кто будет добавлять новые константыnum_getter
template < int i, typename T > struct bindValueCodeOnResultType { typedef typename pair< int_< i >, T > type; }; и в списке типов использовать bindValueCodeOnResultType< 0, int >::type,
Использование traits для обустройства Win32 API