Opened 10 years ago

Last modified 10 years ago

#6961 new Bugs

problem with list_c et.all

Reported by: Robert Ramey Owned by: Aleksey Gurtovoy
Milestone: To Be Determined Component: mpl
Version: Boost 1.49.0 Severity: Problem
Keywords: Cc:

Description

The documentation for list_c states that it is a model of Front Extensible Sequence.

But some simple testing suggests otherwise. Here is my test program:

#include "../include/multi_precision.hpp"

//#include <boost/mpl/shift_right.hpp>
//#include <boost/mpl/integral_c.hpp>
//#include <boost/cstdint.hpp>

#include <boost/mpl/list.hpp>
#include <boost/mpl/list_c.hpp>
#include <boost/mpl/push_front.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/integral_c.hpp>

#include <boost/mpl/print.hpp>

namespace boost {
namespace mpl {

print<
    list_c<int,
       22,
       64 
    >
> x8;

print<
    front< 
        list_c<int,
           22,
           64 
        >
    >::type
> x7;

print<
    push_front< 
        list_c<int,
            22,
            64
        >, 
        integral_c<int, 33> 
    >::type
> x6;


which produces the following output on my VC 9.0 compiler

1>------ Build started: Project: test_interval, Configuration: Debug Win32 ------
1>Compiling...
1>test_multi_precision.cpp
1>c:\boostrelease\boost\mpl\print.hpp(51) : warning C4308: negative integral constant converted to unsigned type
1>        c:\projects\boost projects\mpl\tests\test_multi_precision.cpp(24) : see reference to class template instantiation 'boost::mpl::print<T>' being compiled
1>        with
1>        [
1>            T=boost::mpl::list_c<int,22,64>
1>        ]
1>c:\boostrelease\boost\mpl\print.hpp(51) : warning C4308: negative integral constant converted to unsigned type
1>        c:\projects\boost projects\mpl\tests\test_multi_precision.cpp(33) : see reference to class template instantiation 'boost::mpl::print<T>' being compiled
1>        with
1>        [
1>            T=boost::mpl::integral_c<int,22>
1>        ]
1>c:\boostrelease\boost\mpl\print.hpp(51) : warning C4308: negative integral constant converted to unsigned type
1>        c:\projects\boost projects\mpl\tests\test_multi_precision.cpp(44) : see reference to class template instantiation 'boost::mpl::print<T>' being compiled
1>        with
1>        [
1>            T=boost::mpl::l_item<boost::mpl::long_<3>,boost::mpl::integral_c<int,33>,boost::mpl::list2_c<int,22,64>>
1>        ]

What I hope to see for the third test is:

T=boost::mpl::list_c<int,33, 22,64>

If I use

print<
    push_front< 
        list_c<int,
            22,
            64
        >, 
        33
    >::type
> x5;

But this fails to compile at all.

To me, the list_c implementation is misconceived. Maybe the following should result

print<
    list_c<int,
       22,
       64 
    >::type // note the ::type to make it a metafunction
> x8;

to return

T=boost::mpl::list<boost::mpl::integral_c<int, 22>,boost::mpl::integral_c<int, 64> >

Of course the same observations would apply to vector_c, etc.

Robert Ramey

Change History (1)

comment:1 by Robert Ramey, 10 years ago

FYI - the following works as expected from the docs.

typedef vector_c<int,1,2,3,5,8,13,21> v;

print<
    v::type
> x7;

print<
    push_front<v ,integral_c<int,1> >::type
> x6;

showing:

test_multi_precision.cpp
1>c:\boostrelease\boost\mpl\print.hpp(51) : warning C4308: negative integral constant converted to unsigned type
1>        c:\projects\boost projects\mpl\tests\test_multi_precision.cpp(18) : see reference to class template instantiation 'boost::mpl::print<T>' being compiled
1>        with
1>        [
1>            T=boost::mpl::vector7_c<int,1,2,3,5,8,13,21>
1>        ]
1>c:\boostrelease\boost\mpl\print.hpp(51) : warning C4308: negative integral constant converted to unsigned type
1>        c:\projects\boost projects\mpl\tests\test_multi_precision.cpp(22) : see reference to class template instantiation 'boost::mpl::print<T>' being compiled
1>        with
1>        [
1>            T=boost::mpl::vector8<boost::mpl::integral_c<int,1>,boost::mpl::integral_c<int,1>,boost::mpl::integral_c<int,2>,boost::mpl::integral_c<int,3>,boost::mpl::integral_c<int,5>,boost::mpl::integral_c<int,8>,boost::mpl::integral_c<int,13>,boost::mpl::integral_c<int,21>>
1>        ]
Note: See TracTickets for help on using tickets.