I would like to write a function template that works with a string container, like std::vector .
I would like to support both CString and std::wstring using the same template function.
The problem is that CString and wstring have different interfaces, for example, to get the "length" of a CString , you call the GetLength() method, instead you call size() or length() for wstring.
If we had a "static if" function in C ++, I could write something like:
template <typename ContainerOfStrings> void DoSomething(const ContainerOfStrings& strings) { for (const auto & s : strings) { static_if(strings::value_type is CString) {
Is there any method of programming patterns to achieve this with the currently available C ++ 11/14 tools?
PS
I know that you can write a couple of DoSomething() overloads with vector<CString> and vector<wstring> , but this is not a question question.
Moreover, I would like this function template to work for any container in which you can iterate using a range loop.
c ++ c ++ 11 templates containers compile-time
Mr.C64
source share