boost-mpl

boost::mpl::vector - getting to a type's base-offset

那年仲夏 提交于 2019-12-01 05:12:15
问题 Is it possible to get at the offset of a mpl::vector after performing a mpl::find<seq,type> on it ? Put differently I want to do the compile time equavalent of: #include <vector> #include <algorithm> #include <iostream> int main() { typedef std::vector<int> v_type; v_type v_int(3); v_int[0] = 1; v_int[1] = 2; v_int[2] = 3; v_type::iterator it= std::find( v_int.begin() ,v_int.end(),3); std::cout << it - v_int.begin() << std::endl; } Failing this, my types in mpl::vector have a type_trait<T>:

boost::mpl::for_each without instantiating

試著忘記壹切 提交于 2019-11-30 07:09:15
Taking the following example, I wonder whether there is an alternative to boost::mpl::for_each , which does call a Functor without any arguments. #include <boost/mpl/vector.hpp> #include <boost/mpl/for_each.hpp> struct EasyFixEngineA { static const char* const name() { return "a"; } }; struct EasyFixEngineB { static const char* const name() { return "b"; } }; struct Registrator { // Would prefer a template<class T> void operator()() template<class T> void operator()(T t) { RegisterInFactory<EasyFixEngine, T> dummy(T::name()); } }; // ... typedef boost::mpl::vector<EasyFixEngineA,EasyFixEngineB

Is it possible to iterate an mpl::vector at run time without instantiating the types in the vector?

橙三吉。 提交于 2019-11-30 01:52:16
Generally, I would use boost::mpl::for_each<>() to traverse a boost::mpl::vector , but this requires a functor with a template function declared like the following: template<typename T> void operator()(T&){T::staticCall();} My problem with this is that I don't want the object T to be instantiated by for_each<> . I don't need the T parameter in the operator() at all. Is there a way to accomplish this, or an alternative to for_each<> that doesn't pass an object of type T to the template function? Optimally, I would like the operator() definition to look like this: template<typename T> void

Is there a way to deduce the signature of a lambda as an mpl sequence?

帅比萌擦擦* 提交于 2019-11-29 10:37:27
Is there a way to deduce the signature, result- and parameter-types, of a c++0x lambda as a Boost.MPL sequence, for example a boost::mpl::vector ? For example, for a lambda []( float a, int b ) -> void { std::cout << a << b << std::endl; } I would like to get a boost::mpl::vector<void,float,int> . C++0x lambdas which are "closure-objects" are functors. So you can use boost.Boost.FunctionTypes to decompose its operator() . Example: #include <boost/function_types/parameter_types.hpp> #include <boost/mpl/at.hpp> #include <boost/mpl/int.hpp> int main() { int x = 1; auto f = [x](char a, short b,

boost::mpl::for_each without instantiating

独自空忆成欢 提交于 2019-11-29 08:56:27
问题 Taking the following example, I wonder whether there is an alternative to boost::mpl::for_each , which does call a Functor without any arguments. #include <boost/mpl/vector.hpp> #include <boost/mpl/for_each.hpp> struct EasyFixEngineA { static const char* const name() { return "a"; } }; struct EasyFixEngineB { static const char* const name() { return "b"; } }; struct Registrator { // Would prefer a template<class T> void operator()() template<class T> void operator()(T t) { RegisterInFactory

Boost Spirit kwd parser in Visual Studio 2013

你。 提交于 2019-11-28 11:04:50
问题 I'm using Boost 1.57 with Visual Studio 2010. I would like to upgrade my project to Visual Studio 2013 but i'm having some problem with the boost Spirit parser. Seem to me that the kwd parser is broken somehow. The following code compiles correctly in Visual Studio 2010: #include <boost/spirit/include/qi.hpp> #include <boost/spirit/include/phoenix_core.hpp> #include <boost/spirit/include/phoenix_operator.hpp> #include <boost/spirit/repository/include/qi_kwd.hpp> #include <boost/spirit

Is there a way to deduce the signature of a lambda as an mpl sequence?

﹥>﹥吖頭↗ 提交于 2019-11-28 03:59:38
问题 Is there a way to deduce the signature, result- and parameter-types, of a c++0x lambda as a Boost.MPL sequence, for example a boost::mpl::vector ? For example, for a lambda []( float a, int b ) -> void { std::cout << a << b << std::endl; } I would like to get a boost::mpl::vector<void,float,int> . 回答1: C++0x lambdas which are "closure-objects" are functors. So you can use boost.Boost.FunctionTypes to decompose its operator() . Example: #include <boost/function_types/parameter_types.hpp>

C++ convert integer to string at compile time

ぐ巨炮叔叔 提交于 2019-11-27 13:16:04
I want to do something like this: template<int N> char* foo() { // return a compile-time string containing N, equivalent to doing // ostringstream ostr; // ostr << N; // return ostr.str().c_str(); } It seems like the boost MPL library might allow this but I couldn't really figure out how to use it to accomplish this. Is this possible? First of all, if usually you know the number at run time, you can as easily build the same string. That is, if you have 12 in your program, you can have also "12" . Preprocessor macros can add also quotes to arguments, so you can write: #define STRINGIFICATOR(X)

C++ convert integer to string at compile time

你离开我真会死。 提交于 2019-11-26 18:13:55
问题 I want to do something like this: template<int N> char* foo() { // return a compile-time string containing N, equivalent to doing // ostringstream ostr; // ostr << N; // return ostr.str().c_str(); } It seems like the boost MPL library might allow this but I couldn't really figure out how to use it to accomplish this. Is this possible? 回答1: First of all, if usually you know the number at run time, you can as easily build the same string. That is, if you have 12 in your program, you can have