C++ boost::type_traits::function_traits














































C++ boost::type_traits::function_traits



Description:
boost::function_traits<> will returnt the function traits i.e. its arity, result_type, argN_type
The syntax is given below

Syntax:
boost::function_traits<function(arguments)>::arity                        -->  An integer constant that gives the number of 
                                                                                                                       arguments accepted by the function
boost::function_traits<function(arguments)>::result_type            -->  The type returned by the function
boost::function_traits<function(arguments)>::argN_type              -->  The Nth argument type of function ,                                                                                                                                                                                where 1 <= N <= arity of F


Headers:
#include<boost/type_traits.hpp>
or
#include<boost/type_traits/function_traits.hpp>

Sample Code:
#include<iostream>
#include<boost/type_traits.hpp> //#include<boost/type_traits/function_traits.hpp> using namespace std; int main() { // to print true or false instead of 0 and 1 cout<<boolalpha; // function_traits<>::result_type and fucntion_traits<>::argN_type must be used with typedef typedef boost::function_traits<void(int, float, double, char)>::result_type R; // R = void typedef boost::function_traits<void(int, float, double, char)>::arg2_type A; // A = float // fucntion_traits<>::arity will result int the number of arguments the function takes cout<<boost::function_traits<void()>::arity<<endl; // function_traits<>::result_type results in the return type of the function cout<<"If the fucntion void ( int , float , double , char ) return type is void: "<<boost::is_same<R, void>::value<<endl; // function_traits<>::argN_type results int he type of the Nth argument // if N is out of range of the number of arguments, compiler will throw and error cout<<"If the function's second argument is float: "<<boost::is_same<A, float>::value<<endl; return 0; }

Output:
0 If the function void (int, float, double, char ) return type is void: true If the function's second argument is float: true

More Articles of Ayush Ranjan:

Name Views Likes
C++ boost::type_traits::remove_volatile 597 12
C++ boost::type_traits::is_object 488 6
C++ boost::type_traits::is_destructible 481 1
C++ boost::type_traits::has_nothrow_copy 363 6
C++ boost::type_traits::is_const 458 1
C++boost::EnableIf 604 2
C++ boost::type_traits::has_virtual_destructor 449 5
C++ boost::type_traits::remove_extent 510 4
C++ boost::type_traits::has_post_increment 363 4
C++ boost::type_traits::extent 403 1
C++ boost::type_traits::is_enum 562 11
C++ boost::type_traits::has_unary_minus 479 7
C++ boost::type_traits::has_minus 346 2
C++ boost::type_traits::is_member_pointer 515 14
C++ boost::type_traits::has_divides_assign 322 1
C++ boost::type_traits::has_divides 339 1
C++ boost::type_traits::has_bit_or_assign 383 1
C++ boost::type_traits::has_bit_or 436 1
C++ boost::type_traits::has_equal_to 381 1
C++ boost::type_traits::has_nothrow_constructor 445 3
C++ boost::type_traits::has_negate 398 35
C++ boost::type_traits::has_trivial_move_assign 485 8
C++ boost::type_traits::has_pre_increment 539 10
C++ boost::type_traits::is_virtual_base_of 515 1
C++ boost::type_traits::is_member_object_pointer 504 15
C++ boost::type_traits::remove_reference 482 11
C++ boost::type_traits::rank 427 5
C++ boost::type_traits::is_union 616 11
C++ boost::type_traits::has_unary_plus 408 9
C++ boost::type_traits::remove_const 458 15
C++ boost::type_traits::is_unsigned 509 14
C++ boost::type_traits::add_lvalue_reference 364 1
C++ boost::type_traits::has_less 358 1
C++ boost::type_traitsis_fundamental 428 12
C++ boost::type_traits::has_trivial_destructor 445 23
C++ boost::lambda 712 1
C++ boost::type_traits::decay 393 1
C++ boost::type_traits::copy_cv 406 1
C++ boost::type_traits::aligned_storage 358 1
C++ boost::type_traits::is_member_function_pointer 486 14
C++ boost::type_traits::add_pointer 397 1
C++ boost::type_traits::has_bit_xor 372 1
C++ boost::type_traits::remove_pointer 502 5
C++ boost::type_traits::has_bit_xor_assign 339 1
C++ boost::type_traits::add_rvalue_reference 363 1
C++ boost::type_traits::make_signed 463 4
C++ boost::type_traits::promote 527 21
C++ boost::type_traits::has_bit_and_assign 324 3
C++ boost::type_traits::common_type 379 1
C++ boost::type_traits::is_same 503 0
C++ boost::type_traits::is_rvalue_reference 550 9
C++ boost::type_traits::has_plus 383 21
C++ boost::foreach 1498 1
C++ boost::type_traits::is_compound 472 1
C++ boost::type_traits::add_const 400 1
C++ boost::type_traits::add_cv 493 1
C++ boost::type_traits::has_greater_equal 382 1
C++ boost::type_traits::remove_all_extents 507 9
C++ boost::type_traits::is_array 543 23
C++ boost::type_traits::function_traits 733 1
C++ boost::type_traits::has_nothrow_destructor 367 5
C++ boost::type_traits::has_plus_assign 366 4
C++ boost::type_traits::make_signed 77 9
C++ boost::type_traits::is_base_of 454 17
C++ boost::type_traits::has_post_decrement 418 56
C++ boost::type_traits::is_constructible 510 1
C++ boost::type_traits::has_dereference 337 1
C++ boost::type_traits::is_volatile 500 1
C++ Boost Lambda 699 1
C++ boost::type_traits::has_not_equal_to 399 2
C++ boost::type_traits::is_function 466 17
C++ boost::type_traits::is_abstract 499 18
C++ boost::type_traits::type_with_alignment 569 10
C++ boost::type_traits::has_multiplies 473 16
C++ boost::type_traits::is_final 465 6
C++ boost::type_traits::type_identity 539 9
C++ boost::type_traits::is_assignable 431 33
C++ boost::type_traits::has_greater 334 1
C++ boost::type_traits::has_unary_plus 413 8
C++ boost::type_traits::has_trivial_assign 373 3
C++ boost::type_traits::is_default_constructible 438 2
C++ boost::Type_traits::is_arithmetic 459 21
C++ boost::type_traits::is_complex 767 8
C++ boost::type_traits::has_logical_and 358 1
C++ boost::type_traits::has_pre_decrement 314 0
C++ boost::type_traits::has_left_shift 328 1
C++ boost::type_traits::alignment_of 432 1
C++ boost::type_traits::has_trivial_constructor 407 4
C++ boost::type_traits::has_modulus 357 2
C++ boost::type_traits::is_copy_assignable 395 7
C++ boost::type_traits::is_polymorphic 491 8
C++ boost::type_traits::is_signed 559 9
C++ boost::type_traits::make_unsigned 513 21
C++ boost::type_traits::integral_constant 402 34
C++ boost::type_traits::is_pointer 481 19
C++ boost::type_traits::is_pod 484 17
C++ boost::type_traits::is_integral 587 15
C++ boost::type_traits::has_right_shift_assign 321 10
C++ boost::type_traits::remove_cv 548 6
C++ boost::type_traits::has_logical_not 322 1
C++ boost::type_traits::integral_promotion 399 4
C++ boost::type_traits::has_minus_assign 328 2
C++ boost::type_traits::is_nothrow_move_constructible 472 25
C++ boost::type_traits::declval 372 1
C++ boost::type_traits::has_multiplies_assign 386 46
C++ boost::type_traits::add_volatile 359 1
C++ boost::type_traits::is_nothrow_move_assignable 469 8
C++ boost::type_traits::is_scalar 520 13
C++ boost::type_traits::is_void 522 9
C++ boost::type_traits::is_empty 438 4
Program to check whether a number is Palindrome or not 481 2
C++ boost::type_traits::has_right_shift 377 5
C++ boost::type_traits::left_shift_assign 414 1
C++ boost::type_traits::has_logical_or 436 1
C++ boost::type_traits::add_reference 422 1
C++ boost::type_traits::has_modulus_assign 338 3
C++ boost::type_traits::is_floating_point 459 6
C++ boost::type_traits::is_convertible 444 4
C++ boost::type_traits::is_lvalue_reference 444 7
C++ boost::type_traits::has_new_operator 360 24
C++ boost::type_traits::has_less_equal 328 1
C++ boost::type_traits::has_trivial_move_constructor 368 6
C++ boost::type_traits::is_reference 477 0
C++ boost::type_traits::has_complement 277 1
C++ boost::type_traits::has_bit_and 283 1
C++ boost::type_traits::floating_point_promotion 317 1
C++ boost::type_traits::has_unary_minus 320 10
C++ boost::type_traits::has_nothrow_assgin 416 6
C++ boost::type_traits::has_trivial_copy 315 4
C++ boost::type_traits::is_class 469 14
C++ boost::type_traits::is_copy_constructible 439 13
C++ boost::type_traits::conditional 298 1
C++ boost::type_traits::is_stateless 437 3

Comments