Wednesday, April 18, 2018

c++ - Hiding templated helper function - static members or unnamed namespace

I'm trying to write a library where I have some templated functions, some of which are helper functions so I don't want my users to have access to them. Some basic code might be



//mylib.h

namespace myfuncs
{
template
void helper (T input, int extrainformation)
{

//do some usefull things
}

template
void dostuff(T input)
{
int someinfo=4;
helper(input, someinfo);
}
}



Is it possible to somehow hide the helper function so that users of the library can't call it directly? I had thought an unnamed namespace might do the job but because I'm using templates I can't split the function declaration and body between a header and implementation file. Putting the unnamed namespace in a header file is of no use and bad style. The only thing I can think to do is create a mylib class and encapsulate the functions as private/public static functions.



Any better solutions would be much appreciated.



Phil

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...