boostorg / compute

A C++ GPU Computing Library for OpenCL
http://boostorg.github.io/compute/
Boost Software License 1.0
1.55k stars 333 forks source link

use nested custom type with BOOST_COMPUTE_ADAPT_STRUCT macro #808

Open changephilip opened 5 years ago

changephilip commented 5 years ago

Hello! I use code like below in my program.

struct MyStructA{
          int a;
          int b;
};
BOOST_COMPUTE_ADAPT_STRUCT(MyStructA,MyStructA,(a,b))
struct MyStructB{
          MystructA c;
          int d;
};
BOOST_COMPUTE_ADAPT_STRUCT(MyStructB,MystructB,(c,d))

While I compile the program , the compiler report some errors about redefinition: /boost/compute/type_traits/type_name.hpp:119:24: error: redefinition of 'const char* boost::compute::type_name() [with T= MyStructB]'

I wonder whether I could nested a struct in another struct.

jszuppe commented 5 years ago

I don't thinks that's possible right now. BOOST_COMPUTE_ADAPT_STRUCT would have to know dependencies of the struct it's adapting to inject required type definition into kernels.

I think if you look how BOOST_COMPUTE_ADAPT_STRUCT is implemented, you can implement similar variadic macro (C++11 would be required and/or GNU extension), where the variadic arguments are dependencies (required types).