473,657 Members | 2,419 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

twice(twice(x))

I am having trouble with the function Add4Ptrs_v2.
I thought "twice< add_pointer<_>, _ >" was a perfectly valid
metafunction, but the following code does not work:

#include <iostream>

#include <boost/type_traits.hpp >

#include <boost/mpl/vector.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/times.hpp>

using namespace boost; // ...
using namespace mpl; // ...

// Metafunction class.
struct metaf
{
template<typena me T>
struct apply : public plus< int_<1>, T > {};
};

// Metafunction.
template<typena me F, typename X>
struct twice : public apply< F, typename apply< F, X >::type > {};

// Metafunction: X -> X****
template<typena me X>
struct Add4Ptrs
{
typedef typename twice< add_pointer<_>, typename
twice<add_point er<_>, X>::type >::type type;
};

// Metafunction: X -> X****
template<typena me X>
struct Add4Ptrs_v2
{
typedef typename twice< twice< add_pointer<_>, _ >, X >::type type;
};

int main()
{
typedef transform< vector_c<int,1, 2,3>, metaf >::type res0;
// ok

typedef transform< vector_c<int,1, 2,3>, plus< _, int_<1> > >::type
res1; // 3.1
typedef transform< vector_c<int,1, 2,3>, times< _, _1 > >::type
res2; // 3.2
typedef Add4Ptrs<int>:: type res3;
// 3.3
typedef Add4Ptrs_v2<int >::type res4;
// 3.4

std::cout << typeid(res0).na me() << std::endl << std::endl;
std::cout << typeid(res1).na me() << std::endl << std::endl;
std::cout << typeid(res2).na me() << std::endl << std::endl;
std::cout << typeid(res3).na me() << std::endl << std::endl;
std::cout << typeid(res4).na me() << std::endl << std::endl;
}
<<<<

Kiuhnm
Apr 1 '06 #1
2 1625
Kiuhnm" <"kiuhnm03[ wrote:
I am having trouble with the function Add4Ptrs_v2.
I thought "twice< add_pointer<_>, _ >" was a perfectly valid
metafunction, but the following code does not work:
>

#include <iostream>

#include <boost/type_traits.hpp >

[...]

You should consider Boost's online forums for questions about their
functionality. Here we talk standard C++ only.

V
--
Please remove capital As from my address when replying by mail
Apr 1 '06 #2
Victor Bazarov ha scritto:
You should consider Boost's online forums for questions about their
functionality. Here we talk standard C++ only.


Ok, sorry.

Kiuhnm
Apr 1 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.