K
Kiuhnm
I am having trouble with the function Add4Ptrs_v2.
#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
#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