473,385 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Order of template specializations

Hi,

I have a templated class field:
template <typename Value_Type>
class Field
{
public:
Value_Type value;
};

I want to load the value member from an std::istream.
I want to use a special algorithm for string fields,
but the extraction operators for all others.

My question is: does the overloaded function have
to be declared before the template version?

void LoadField(Field<string>& sf, istream & inp)
{
// ...
}

template <typename Value_Type>
void LoadField(Field<Value_Type>& vf, istream & inp)
{
// ...
}

I would like to create specializations for the
Field<string> and place them in a different
translation unit than the one in which Field is
defined.

The idea is that when somebody wants a Field<double>
they don't get all the function declarations for
Field<string>.

This example was simplified from my actual code.
My actual design is:
Field
^
|
Typed_Field (template)
^
|
Sortable_Typed_Field

typedef Sortable_Typed_Field<int> Integer_Field;
typedef Sortable_Typed_Field<string> String_Field;

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #1
1 1248
Thomas Matthews wrote in news:73t%b.50137$hd3.31340
@newssvr33.news.prodigy.com:
Hi,

I have a templated class field:
template <typename Value_Type>
class Field
{
public:
Value_Type value;
};

I want to load the value member from an std::istream.
I want to use a special algorithm for string fields,
but the extraction operators for all others.

My question is: does the overloaded function have
to be declared before the template version?

No, but it needs to be declared in all TU's that might use it.
void LoadField(Field<string>& sf, istream & inp)
{
// ...
}

template <typename Value_Type>
void LoadField(Field<Value_Type>& vf, istream & inp)
{
// ...
}

I would like to create specializations for the
Field<string> and place them in a different
translation unit than the one in which Field is
defined.
If they're overloads of fully explicit specialization's then
declare them in a header, and define them elsewhere.

The idea is that when somebody wants a Field<double>
they don't get all the function declarations for
Field<string>.


Just in case:

- A declaration:

int f();

- A Defenition (also a declaration):

int f()
{
}

They need to see all possible declaration's but not all
defenition's.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: NKOBAYE027 | last post by:
FIRST POST Hi All: I'm trying to write a simple specialization before moving on to something a bit more complex - always a good idea in my case, at least. :o) I'm trying to adapt the example...
1
by: Imre | last post by:
Let's suppose we have a primary template with one argument defined in a header file. Two source files include this header, and both define a specialization of the primary template. Later, both...
1
by: Samee Zahur | last post by:
Why aren't we allowed to do partial specializations like these on numeric template parameters? That would have allowed us to do all kinds of interesting stuffs like loops of variable nesting (bad...
4
by: Alfonso Morra | last post by:
Does VC 7.1 support template specialization and partial specialization ?
2
by: Joseph Turian | last post by:
I'm posting this question for a friend who lacks USENET access. He and I were discussing this question and could not figure out the solution. Thank you for your help Joseph ===
4
by: stinos | last post by:
Hi All! suppose a class having a function for outputting data somehow, class X { template< class tType > void Output( const tType& arg ) { //default ToString handles integers/doubles
16
by: Hendrik Schober | last post by:
Hi, suppose we have template< typename T > struct X; and some specializations: template<>
1
by: jason.cipriani | last post by:
Here is an example with 3 files, containing a template structure and also a template function. The header A.h declares a template structure A with a default (i.e. for any template parameter),...
5
by: (2b|!2b)==? | last post by:
I would like to know if I can specialize only a specific method for a class template. Is the (specialization) code below valid? template <typename T1, typename T2> class MyClass { public:
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.