LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-30-2009, 01:09 AM   #1
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 444

Rep: Reputation: 30
How do I make a template char* or wchar_t* default function argument


I have a template similar to the following.
Code:
template <charT>
virtual void do_get_date(charT* = "str")
{ ... }
As you can see we have a problem. If we use a wchar_t instead the string wont be formatted right we need to prefix L in front. If we use char16_t we need to prefix a u in front. Is there a was to make the generic without resorting the the std::string class?
 
Old 10-30-2009, 01:31 AM   #2
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
I'd suggest that you use plain old overloading here. There's no point in making it more generic than it actually needs to be.

Though, *why* do you want to do this? Most apps that actually bother to localize enforce the use of either UTF-8 std::string or std::wstring but not both. Mixing the two is a classic way to set yourself up to shooting yourself in the foot.
 
Old 10-30-2009, 01:46 AM   #3
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 444

Original Poster
Rep: Reputation: 30
I just wanted to see if a general solution existed. I'm just reading over character sets and am trying to understand unicode. L must be a macro defined somewhere but I don't even know what it does. All attemps to find this macro using ctags have failed for me. I wonder if gcc just generates the macro. Maybe you could help. Unicode constists of 32 bits or a qword. Each qword contains a character of a place for character expansion (to my understanding). How does the formatting go. Say I wanted to type one of the Japanese alphabets. Which byte would contain what?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C++: different instances of a function template unihiekka Programming 3 02-05-2009 01:50 PM
pthread, passing char* as data argument Rayven Programming 3 03-22-2007 05:36 AM
C++ Template For Generic Function - Is This Possible? taylor_venable Programming 6 06-05-2006 08:46 PM
unsigned char to wchar_t JurajPsycho Programming 6 03-19-2005 04:00 PM
function prototypes in template class' (c++) qwijibow Programming 4 12-13-2004 09:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:55 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration