Changeset 10981 for code/branches/cpp11_v2/src/libraries/core
- Timestamp:
- Dec 27, 2015, 11:04:09 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v2/src/libraries/core/command/Functor.h
r10980 r10981 415 415 { enum { result = false }; }; 416 416 417 // Helper class to determine the N-th parameter of a variadic template (with 0 being the index of the first parameter) 418 template <int n, typename T = void, typename... Other> 419 struct GetNthParamType 420 { typedef typename GetNthParamType<n - 1, Other...>::Type Type; }; 421 template <typename T, typename... Other> 422 struct GetNthParamType<0, T, Other...> 423 { typedef T Type; }; 424 417 425 //Barebones implementation of (make_)index_sequence for C++11 418 426 template <std::size_t...> struct index_sequence {}; … … 437 445 }; 438 446 447 template <class T1> 448 struct make_type_list_helper<T1> 449 { 450 template <std::size_t N, class... Types> 451 struct make_type_list_impl : type_list<Types..., T1> {}; 452 }; 453 439 454 template <std::size_t N, class... Types> 440 455 struct make_type_list : make_type_list_helper<Types...>::template make_type_list_impl<N> {}; … … 442 457 template <class... Types> 443 458 struct make_type_list<0u, Types...> : type_list<> {}; 459 460 template <std::size_t N> 461 struct make_type_list<N> : type_list<> {}; 462 463 template <> 464 struct make_type_list<0u> : type_list<> {}; 444 465 } 445 466 … … 485 506 virtual void evaluateArgument(unsigned int index, MultiType& argument) const override 486 507 { 487 static const std::array<std::function<bool(MultiType&)>, sizeof...(Params)> funcs = {&MultiType::convert<Params>...}; 488 if (index < funcs.size()) 508 switch (index) 489 509 { 490 funcs[index](argument); 510 case 0: argument.convert<typename detail::GetNthParamType<0, Params...>::Type>(); break; 511 case 1: argument.convert<typename detail::GetNthParamType<1, Params...>::Type>(); break; 512 case 2: argument.convert<typename detail::GetNthParamType<2, Params...>::Type>(); break; 513 case 3: argument.convert<typename detail::GetNthParamType<3, Params...>::Type>(); break; 514 case 4: argument.convert<typename detail::GetNthParamType<4, Params...>::Type>(); break; 491 515 } 492 516 } … … 507 531 virtual std::string getTypenameParam(unsigned int index) const override 508 532 { 509 static const std::array<std::string, sizeof...(Params)> names = { typeToString<Params>()... }; 510 if (index >= names.size()) 533 switch (index) 511 534 { 512 return ""; 535 case 0: return typeToString<typename detail::GetNthParamType<0, Params...>::Type>(); 536 case 1: return typeToString<typename detail::GetNthParamType<1, Params...>::Type>(); 537 case 2: return typeToString<typename detail::GetNthParamType<2, Params...>::Type>(); 538 case 3: return typeToString<typename detail::GetNthParamType<3, Params...>::Type>(); 539 case 4: return typeToString<typename detail::GetNthParamType<4, Params...>::Type>(); 540 default: return ""; 513 541 } 514 return names[index];515 542 } 516 543 … … 530 557 virtual const std::type_index getHeaderIdentifier(unsigned int params) const override 531 558 { 532 //+1 because e.g. for two parameters, we want typeids for zero, one, or two parameters 533 return getHeaderIdentifierHelper(params, detail::make_index_sequence<sizeof...(Params) + 1>{}); 559 switch (params) 560 { 561 case 0: return this->getTypelistIdentifier(detail::make_type_list<0, Params...>{}); 562 case 1: return this->getTypelistIdentifier(detail::make_type_list<1, Params...>{}); 563 case 2: return this->getTypelistIdentifier(detail::make_type_list<2, Params...>{}); 564 case 3: return this->getTypelistIdentifier(detail::make_type_list<3, Params...>{}); 565 case 4: return this->getTypelistIdentifier(detail::make_type_list<4, Params...>{}); 566 default: return this->getTypelistIdentifier(detail::make_type_list<5, Params...>{}); 567 } 534 568 } 535 569 536 570 private: 537 538 571 /// Helper function that extracts index numbers of parameters from a tuple. Needed to call the function pointer with the correct amount of arguments. 539 572 template<typename Tup, std::size_t... index> … … 541 574 { 542 575 return detail::FunctorCaller<R, O, isconst, Params...>::call(this->functionPointer_, object, std::get<index>(std::forward<Tup>(tup))...); 543 }544 545 /// Helper function to extract all identifiers of the function pointer using a deduced index sequence546 template<std::size_t... index>547 const std::type_index& getHeaderIdentifierHelper(unsigned int params, detail::index_sequence<index...>) const548 {549 static const std::array<const std::type_index, sizeof...(index)> typeinfos = { getTypelistIdentifier(detail::make_type_list<index, Params...>{})... };550 if (params >= typeinfos.size())551 {552 return typeinfos.back();553 }554 return typeinfos[params];555 576 } 556 577
Note: See TracChangeset
for help on using the changeset viewer.