Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > twice(twice(x))

Reply
Thread Tools

twice(twice(x))

 
 
Kiuhnm
Guest
Posts: n/a
 
      04-01-2006
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<typename T>
struct apply : public plus< int_<1>, T > {};
};

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

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

// Metafunction: X -> X****
template<typename 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).name() << std::endl << std::endl;
std::cout << typeid(res1).name() << std::endl << std::endl;
std::cout << typeid(res2).name() << std::endl << std::endl;
std::cout << typeid(res3).name() << std::endl << std::endl;
std::cout << typeid(res4).name() << std::endl << std::endl;
}
<<<<

Kiuhnm
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      04-01-2006
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


 
Reply With Quote
 
 
 
 
Kiuhnm
Guest
Posts: n/a
 
      04-01-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments