Hi,
I am trying to make a template for building sequences of random numbers
using Boost.Mpl, but apparently I haven't quite got the hang of it yet
;). Below is my code (adapted from the Boost.Random docs) and the
compiler output (GCC v 3.4.2), I seem to have misunderstood the usage of
mpl::first and mpl::second in lambdas or something. Can someone clarify
what I've done wrong? The whole construct should be invoked with
something like
typedef utils::make_random_sequence::type random_vector;
to generator a vector_c of 10 random numbers.
Thanks,
Mark
#include <cstdlib>
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
namespace utils
{
using namespace boost::mpl;
template
struct random :
integral_c<
T,
template Formula::apply<seed>::value
>
{
typedef random next;
template<T new_seed>
struct reseed
{
typedef random type;
};
};
template
struct linear_congruential
{
BOOST_STATIC_ASSERT(boost::is_integral<IntType>::value);
typedef IntType value_type;
template<IntType seed>
struct apply : integral_c
{
};
};
typedef random<
long,
linear_congruential,
1043618065L
> minstd_rand0;
typedef random<
long,
linear_congruential,
399268537L
> minstd_rand;
template
struct make_random_sequence
{
typedef typename iter_fold<
range_c,
pair<
typename erase<
integral_sequence,
begin,
end
>::type,
generator
>,
pair<
push_back<
first<_1>,
second<_1>
>::type,
second<_1>::next
>
>::type type;
};
}
28: error: missing `>' to terminate the template argument list
28: error: template argument 2 is invalid
28: error: expected `{' before "template"
28: error: expected unqualified-id before "template"
28: error: expected `;' before "template"
C:/Boost/include/boost-1_33/boost/mpl/pair.hpp: In instantiation of
`boost::mpl::first':
C:/Boost/include/boost-1_33/boost/mpl/aux_/has_tag.hpp:20:
instantiated from `boost::mpl::aux::has_tag,
mpl_::bool_< false> >'
C:/Boost/include/boost-1_33/boost/mpl/sequence_tag.hpp:115:
instantiated from `boost::mpl::sequence_tag >'
C:/Boost/include/boost-1_33/boost/mpl/push_back.hpp:32: instantiated
from `boost::mpl::push_back,
boost::mpl::second >'
85: instantiated from here
C:/Boost/include/boost-1_33/boost/mpl/pair.hpp:43: error: no type named
`first' in `struct mpl_::_1'
85: error: `type' is not a member of
`boost::mpl::push_back,
boost::mpl::second >'
85: error: `type' is not a member of
`boost::mpl::push_back,
boost::mpl::second >'
C:/Boost/include/boost-1_33/boost/mpl/pair.hpp: In instantiation of
`boost::mpl::second':
86: instantiated from here
C:/Boost/include/boost-1_33/boost/mpl/pair.hpp:56: error: no type named
`second' in `struct mpl_::_1'
86: error: `next' is not a member of `boost::mpl::second'
86: error: `next' is not a member of `boost::mpl::second'
88: error: template argument 1 is invalid
88: error: template argument 2 is invalid
88: error: template argument 3 is invalid
88: error: `type' does not name a type