Need some help

I am stuck. The problem is to write a ternary metafiction replace_type<C,X,Y> that takes an arbitrary compound type C as its first parameter and replaces all occurrences of a type X with C with Y.

I have been working and for some simple types C I get it to work but then it seems there are infinite combinations of forms to create a compound C and do not know how to approach this general question. For specific cases, I can solve it but not for general cases

Regards,
Juan

P.S.: This exercise appears in "C++ Metaprogramming" by David Abrahams and Aleksey Gurtovoy...
closed account (48T7M4Gy)
metafiction?
Last edited on
closed account (48T7M4Gy)
2-1. Write a ternary metafunction replace_type<c,x,y> that takes an arbitrary compound type c as its first parameter, and replaces all occurrences of a type x within c with y:

1
2
3
4
5
6
7
8
9
10
11
12
typedef replace_type< void*, void, int >::type t1; // int*
    typedef replace_type<
        int const*[10]
      , int const
      , long
    >::type t2; // long* [10]

    typedef replace_type<
        char& (*)(char&)
      , char&
      , long&
    >::type t3; // long& (*)(long&) 



You can limit the function types you operate on to those with fewer than two arguments.
Hi Juan,

Not sure whether you know that gentleguy is a troll, of closed_account infamy. Consider just ignoring anything that is said by this user - I'll bet he has no idea at all about TMP - any info that he does provide will just be misinformation. Perhaps you could privately approach someone who has helped you in the past ? Up to you to do whatever you want - just trying to help you wasting some time :+)

Regards :+)
Topic archived. No new replies allowed.