twice(twice(x))

Discussion in 'C++' started by Kiuhnm, Apr 1, 2006.

  1. Kiuhnm

    Kiuhnm Guest

    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
     
    Kiuhnm, Apr 1, 2006
    #1
    1. Advertising

  2. 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
     
    Victor Bazarov, Apr 1, 2006
    #2
    1. Advertising

  3. Kiuhnm

    Kiuhnm Guest

    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
     
    Kiuhnm, Apr 1, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lewis
    Replies:
    1
    Views:
    4,099
    Lewis
    Aug 20, 2003
  2. Tom Vande Stouwe MCSD.net

    Re: asp Page events execute twice after PostBack again

    Tom Vande Stouwe MCSD.net, Aug 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    2,471
    Daisy
    Sep 3, 2003
  3. Tony Dong

    asp.net page load twice problem

    Tony Dong, Jun 2, 2005, in forum: ASP .Net
    Replies:
    11
    Views:
    39,553
    BillFR
    Sep 1, 2011
  4. kitty
    Replies:
    0
    Views:
    580
    kitty
    Jul 18, 2005
  5. kitty
    Replies:
    0
    Views:
    436
    kitty
    Jul 18, 2005
Loading...

Share This Page