Questions tagged [boost-mpl]

The Boost.MPL library is a general-purpose, high-level C++ template metaprogramming framework of compile-time algorithms, sequences and metafunctions. It provides a conceptual foundation and an extensive set of powerful and coherent tools that make doing explicit metaprogramming in C++ as easy and enjoyable as possible within the current language.

The Boost.MPL library is a general-purpose, high-level C++ template metaprogramming framework of compile-time algorithms, sequences and metafunctions. It provides a conceptual foundation and an extensive set of powerful and coherent tools that make doing explicit metaprogramming in C++ as easy and enjoyable as possible within the current language.

289 questions
30
votes
8 answers

Examples of practical usage of Boost::MPL?

Can you share any real-world examples of Boost::MPL usage (except lambdas), just to let me better understand its purposes and field of practical usage? The MPL documentation tutorial has a dimensional analysis example, but maybe because it's such an…
Andriy Tylychko
  • 15,967
  • 6
  • 64
  • 112
24
votes
6 answers

C++ convert integer to string at compile time

I want to do something like this: template 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…
Andrey
  • 808
  • 2
  • 6
  • 12
24
votes
6 answers

Loosely coupled implicit conversion

Implicit conversion can be really useful when types are semantically equivalent. For example, imagine two libraries that implement a type identically, but in different namespaces. Or just a type that is mostly identical, except for some…
ltjax
  • 15,837
  • 3
  • 39
  • 62
21
votes
6 answers

How to explicitly instantiate a template for all members of MPL vector in C++?

Consider the following header file: // Foo.h class Foo { public: template void read(T& value); }; I want to explicitly instantiate the Foo::read member function template in a source file for all types included in a…
Daniel Langr
  • 22,196
  • 3
  • 50
  • 93
18
votes
6 answers

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

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 void operator()(T&){T::staticCall();} My problem with this is…
Marcin
  • 12,245
  • 9
  • 42
  • 49
15
votes
3 answers

Permutations of a List of Types Using boost::mpl

I am trying to create a list containing the permutations of a given type list. The below code seems to function, though without the intended result, when I use a specified list instead of generating a new list by removing from the actual input.…
Edward
  • 153
  • 1
  • 5
14
votes
1 answer

C++14 type lists, any reason to prefer 'free functions' to 'methods' or vice versa?

I see two possible styles for implementing type lists in C++11/14 and I was curious if there's any reason to prefer one over the other. The first technique is outlined here and models itself on Boost's MPL library. In this style you define meta…
Joseph Garvin
  • 20,727
  • 18
  • 94
  • 165
14
votes
1 answer

Optimizing compile-time performance by caching metafunctions

Let's say I have the following metafunction: template struct make_pair { using type = std::pair< typename std::remove_reference::type, typename std::remove_reference::type >; }; Would it improve…
13
votes
1 answer

boost mpl string

Hi in boost mpl documentation I have discovered mpl::string and the following example: typedef mpl::string<'hell','o wo','rld'> hello; I'm a little bit surprised because I thought that in C or C++ we can't have more than one character between the…
Guillaume Paris
  • 10,303
  • 14
  • 70
  • 145
12
votes
2 answers

Why does Boost MPL have integral constants?

Since you can take integral values as template parameters and perform arithmetic on them, what's the motivation behind boost::mpl::int_<> and other integral constants? Does this motivation still apply in C++11?
Brent
  • 4,153
  • 4
  • 30
  • 63
11
votes
2 answers

Difference between boost::MPL and boost::fusion

I'm new to boost::fusion and boost::mpl libraries. Could anyone please tell me the main difference between these two libraries? Until now I used only fusion::vector and few other simple things. Now I want to use fusion::map or MPL::map but I don't…
Ludek Vodicka
  • 1,610
  • 1
  • 18
  • 33
11
votes
2 answers

Is there a way to break out of boost::mpl for_each?

Simple question really, let me give some background: I have a mpl::vector of types where each type has an id, at run time I use the mpl::for_each to iterate through this vector and find the matching type for the given id. But once found, there is no…
Nim
  • 33,299
  • 2
  • 62
  • 101
11
votes
3 answers

How do I convert a C string to a int at compile time?

I want to be able to pass an integer or a double (or a string) as a template argument and in some instances convert the result to an integer and use it as a template argument for a type in the class. Here's what I've tried: template
quant
  • 21,507
  • 32
  • 115
  • 211
11
votes
1 answer

Boost MPL Placeholders and Lambda

I am currently doing some proof on concept samples with boost::mpl and am having some difficulties in understanding how the lambda function enables the use of placeholders. I realize that I can wrap metafunctions in metafunction classes to enable…
Blair Davidson
  • 901
  • 12
  • 35
10
votes
2 answers

boost::mpl::for_each without instantiating

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 #include struct EasyFixEngineA { static const…
abergmeier
  • 13,224
  • 13
  • 64
  • 120
1
2 3
19 20