Boost.FunctionTraitsについて

  • boost::functionとboost::function_traitsは関数ポインタ型をサポートしていない
  • function_traitsはわざわざadd_pointerしたあと、Specializationしている
  • おそらく使用の推奨されないfuncionalのunary_traitsとbinary_traitsはサポートしている
  • それらの代替としてMetafunctionの集合であるBoost Function Traitsが開発中
  • Function Objectのfunction_traitsはoperator()がtemplateの場合があるので本来的にサポートできない


[]#include[] <[]boost[]/t[]ype_traits[].[]hpp[]>
[]#include[] <[]boost[]/f[]unction[].[]hpp[]>
[]#include[] <[]boost[]/f[]unctional[].[]hpp[]>
[]#include[] <[]boost[]/m[]pl[]/a[]t[].[]hpp[]>
[]#include[] <[]string[]>

[]// mpl-style-function_traits[]
[]// http://www.kangaroologic.com/function_traits/[]
[]#include[] <[]boost[]/t[]ype_traits[]/f[]unction_arguments[].[]hpp[]>


[]namespace[] []pst_2005_02_15[] {
[]using[] []namespace[] []std[];
[]namespace[] []bst[] = []boost[];
[]namespace[] []mpl[] = []boost[]::[]mpl[];

[]typedef[] []float[] (*[]your_function_ptr_type[]) ([]string[], []double[]);
[]inline[] []float[] []func[]([]string[], []double[]) { []return[] []1[].[]0F[]; }

[]void[] []test[]() {
[]// bst::function<float (*) (int, double)> a_f1; // error![]
[]bst[]::[]function[]<[]float[] ([]string[], []double[])> []a_f1[](&[]func[]);

[]// bst::function<your_function_ptr_type> a_f(&func); // error![]
[]bst[]::[]function[]< []bst[]::[]remove_pointer[]<[]your_function_ptr_type[]>::[]type[] > []a_f[](&[]func[]);

[]// bst::function_traits<your_function_ptr_type>::arg1_type a_str1("hello"); // error![]
[]bst[]::[]function_traits[]< []bst[]::[]remove_pointer[]<[]your_function_ptr_type[]>::[]type[] >::[]arg1_type[]
[]a_str1[]([]"awkward..."[]);

[]// good old days[]
[]bst[]::[]binary_traits[]<[]float[] ([]string[], []double[])>::[]first_argument_type[] []a_str2[]([]"hello"[]);
[]bst[]::[]binary_traits[]<[]your_function_ptr_type[]>::[]first_argument_type[] []a_str3[]([]"hi"[]);

[]// non boostandard[]
[]typedef[] []bst[]::[]function_arguments[]<[]float[] ([]string[], []double[])>::[]type[] []args1[];
[]typedef[] []bst[]::[]function_arguments[]<[]your_function_ptr_type[]>::[]type[] []args2[];
[]mpl[]::[]at_c[]<[]args1[], []0[]>::[]type[] []a_str4[]([]"best!"[]);
[]mpl[]::[]at_c[]<[]args2[], []1[]>::[]type[] []a_int[] = []14[];
}
}