Re: Need VC6 workaround for function template

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Daniel Lidström wrote:
namespace SF
{

Just one suggestion here, though not related to the problem at hand: you can
use a real name for the namespace (namespace sweet_functions {...}) and
then use a namespace alias (namespace sf = sweet_functions;) to keep code
short.

template<class Target, class Source>
std::vector<Target>
Split(const Source& s, typename Source::const_pointer delims)
{...}

std::vector<std::string> Split(const std::string& s,
std::string::const_pointer delims)
{...}

std::vector<std::wstring> Split(const std::wstring& s,
std::wstring::const_pointer delims)
{...}

VC6 says main.cpp(30) : error C2668: 'Split' : ambiguous call to
overloaded function This is in the std::vector<std::string> Split(const
std::string& s, std::string::const_pointer delims) function. Is there a
workaround to make this code compile with VC6?

I think that the trick is to first define the normal functions and then the
templates. This might require creating another template function (e.g.
DoSplit) which the two concrete ones and the template delegate their calls
to.

There's another problem still: VC6's compiler has a bug that it only
includes the parameters that are passed to a function into the mangled
name. For normal functions, which you can't overload on their return type
that is enough, but for template functions it means that you must
artificially introduce the return-type into the passed parameters. In your
case I don't understand why the Target type needs to be different than the
Source type, but it would look like this:

template<typename Target, typename Source>
vector<Target>
Split( Source const& s, typename Source::const_pointer delims
#if defined(_MSC_VER) && _MSC_VER<1300
// compilers before that of VC7 fail to mangle all template parameters
// into the symbol, introduce them here artificially.
, Target const* =0
#endif
)
{...}


Other than that, projects like STLport or Boost are full of cludges to make
them work sufficiently with old, sub-standard compilers like that of VC6.
You might get some wisdom there.

Uli

.



Relevant Pages

  • Re: Adding Forms to the Namespaces
    ... I do not find a good method to customize the namespace of an existing ... item template for VB.NET Form that can be found in the folder C:\Program ... We can either use Visual Studio to export templates and create such an item ... entering the custom namespace name and class name. ...
    (microsoft.public.vsnet.ide)
  • Re: Adding Forms to the Namespaces
    ... I do not find a good method to customize the namespace of an existing ... item template for VB.NET Form that can be found in the folder C:\Program ... entering the custom namespace name and class name. ... Install the UserInputForm Assembly into the Visual Studio installation sub ...
    (microsoft.public.vsnet.ide)
  • Re: GCC
    ... The header names changed explicitly to ... The Standard says that the standard ... that did not put iostream into the std namespace. ... and compilers change along with them. ...
    (Debian-User)
  • Exchange 2003 to 2003 Migration - Kickin it Old-School Style
    ... I am in the middle of a AD 2000/Exchange2003 to AD2008/Exchange2003 inter-forest migration using ADMT 3.1: I need to know how email routes during an ADMT migration to recipients in the source from recipients in the target using a shared SMTP namespace. ... corp.com (and set the "this server is responsible for all mail to this name") this is so that this server will generate NDR since this is the last server in the "chain". ...
    (microsoft.public.exchange.setup)
  • Re: Exchange 2003 to 2003 Migration - Kickin it Old-School Style
    ... There are two ways to route mail for a shared namespace. ... in the target organization also has address a@xxxxxxxxxxxxxxxxx A contact ... it's part of what makes an interorganizational migration ... corp.com (and set the "this server is responsible for all ...
    (microsoft.public.exchange.setup)