alias template import and export from/to DLL

My class has a alias template,

1
2
3
4
5
6
class XXX_API Foo
{
// codes
template <typename Value> Id2Values = std::map<std::string, std::vector<Value>>;
// other codes
};


usually, if you have a template function, you need explicitly export instantiate to the API, my question is what about alias template? Do I need to instantiate each alias? And if I do need to do this, what is the syntax? Thanks.
Last edited on
What do you mean by 'instantiate'? If you want an instance of a templated class you need of course provide the template arguments.

For Id2Values Foo is the scope similar to namespace. You access it this way:

1
2
3
{
  Foo::Id2Values<int> id_val_with_int;
}
template function always need to explicitly instantiate and export to API, do I need to instantiate all possible alias template and export to API, this is my question.

In code maybe it is less confusing

1
2
3
4
5
#include "Foo.h"

template void XXX_API Foo::loo(double val); // export to API
template void XXX_API Foo::loo(int val); // export to API
template void XXX_API Foo::loo(unsigned val); // export to API 


For template alias do I need to do similar things too?

1
2
template using XXX_API Id2Values<double> ; // export alias to API, syntax likely is wrong
template using XXX_API Id2Values<double> ; // export alias to API, syntax likely is wrong 


If there is no need to export template alias, why for functions I need but alias not?
Last edited on
template function always need to explicitly instantiate and export to API
No. I think that you get the terms 'instantiate' and 'export' wrong somehow.

If there is no need to export template alias, why for functions I need but alias not?
What you need in case of template is the [header] file(s) where everything necessary for that template is defined. I don't know what 'export' in this case means.

What is XXX_API?
Last edited on
> For template alias do I need to do similar things too?

No. The alias template would be defined in the header; the user would include the header and use it.


> If there is no need to export template alias, why for functions I need but alias not?

An alias template defines a family of types. Types are used at compile-time.

A function template defines a family of functions; the explicit instantiations are used at link-time.
Topic archived. No new replies allowed.