Boost logo

Boost Users :

Subject: Re: [Boost-users] [MPL] unique not working?
From: Gordon Woodhull (gordon_at_[hidden])
Date: 2013-10-13 23:56:13


> On Oct 13, 2013, at 11:44 PM, Michael Marcin <mike.marcin_at_[hidden]> wrote:
>
> I pass a mpl::vector with duplicates to mpl::unique and the result still has duplicates.
> What am I doing wrong?

Just like std::unique, the duplicated elements must be consecutive for mpl::unique to find them.
Otherwise the complexity wouldn't be linear.

>
> http://coliru.stacked-crooked.com/a/fe85b5739eb4c15f
>
> #include <boost/mpl/vector.hpp>
> #include <boost/mpl/unique.hpp>
> #include <boost/mpl/equal_to.hpp>
> #include <boost/mpl/placeholders.hpp>
> #include <boost/type_traits/is_same.hpp>
> #include <boost/mpl/print.hpp>
>
> template< typename... Args >
> void test( const Args&... args )
> {
> using namespace boost::mpl;
> using namespace boost::mpl::placeholders;
> typedef vector<Args...> args_types;
> typedef typename unique<args_types,
> boost::is_same<_1, _2> >::type unique_types;
> print< unique_types > x;
> }
>
> int main()
> {
> int a = 0;
> char b = 0;
> test( a, b, a );
> }
>
>
> + g++-4.8 -std=c++11 -O2 -Wall -pedantic -pthread main.cpp
> main.cpp: In instantiation of ‘void test(const Args& ...) [with Args = {int, char, int}]’:
> main.cpp:22:19: required from here
> main.cpp:15:27: warning: unused variable ‘x’ [-Wunused-variable]
> print< unique_types > x;
> ^
> + ./a.out
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net