Ticket #2335: insert_same_repeat.cpp

File insert_same_repeat.cpp, 1.6 KB (added by cppljevans@…, 13 years ago)

test driver to demo bug

Line 
1//Purpose:
2// Demonstrate the EBCO problem mentioned here in thread:
3// http://lists.boost.org/boost-users/2008/09/40552.php
4//Result:
5// Problem doesn't occur with gcc snapshot:
6// ftp://gcc.gnu.org/pub/gcc/snapshots/4.4-20090519/gcc-4.4-20090519.tar.bz2
7//
8
9#include <boost/mpl/transform.hpp>
10#include <boost/mpl/always.hpp>
11#include <boost/mpl/range_c.hpp>
12#include <boost/mpl/front_inserter.hpp>
13#include <boost/fusion/include/vector.hpp>
14#include <boost/fusion/include/mpl.hpp>
15
16#include <iostream>
17#include <typeinfo>
18
19namespace boost{namespace mpl{
20 template
21 < typename T
22 , typename Inserter
23 , unsigned Size=0
24 >
25struct insert_same_repeat
26/**@brief
27 * Repeat Inserter Size times on same value, T.
28 *
29 * The body of this template is essentially
30 * a copy of Steven's code in the thread
31 * mentioned in Purpose: above.
32 */
33{
34 // create a sequence of Size elements:
35 typedef boost::mpl::range_c<int, 0, Size> range;
36 // convert all the elements to T with Inserter:
37 typedef typename boost::mpl::transform
38 <range, boost::mpl::always<T>, Inserter>::type
39 type;
40};
41
42}}
43
44int main() {
45 unsigned const count=2;
46 typedef
47 boost::mpl::insert_same_repeat
48 < float
49 , boost::mpl::front_inserter<boost::fusion::vector<> >
50 , count
51 >::type
52 float_container_type;
53 float_container_type float_container_valu;
54 std::size_t size_float=sizeof(float);
55 std::cout << typeid(float_container_type).name() << std::endl;
56 std::cout << "count*sizeof(float)="<<count*size_float<< std::endl;
57 std::cout << "sizeof(float_container_type)="<<sizeof(float_container_type)<< std::endl;
58}