Hi,
I am probably asking for something which was discussed several times,
but all my researches were unsucessfull.
If you look at this code (simplified part of my project):
---------------
template< int dimension > struct Test
{
template< class A > struct assignement
{
template< int I > struct recurse
{
enum { Counter = I + 1 };
static inline void assign( void* v, const A& a )
{
recurse<Counter >::assign( v, a );
}
};
template<> struct recurse<dimensi on>
{
enum { Counter = dimension + 1 };
static inline void assign( void*, const A& )
{
}
};
static inline void assign( void* v, const A& a )
{
recurse<0>::ass ign( v, a );
}
};
};
---------
This code compiles fine with vs2005, but not with g++, which gives me
errors on my specialization template<> struct recurse<dimensi on>:
error: invalid explicit specialization before '>' token
error: explicit specialization in non-namespace scope `struct
Test<dimension> ::assignement<A >'
error: enclosing class templates are not explicitly specialized
error: template parameters not used in partial specialization:
error: `A'
Even though i thought this was completely correct, i tried to put it
outside the class definition, but couldnt get it working.
So i am wondering if what i am doing is actually proper c++, or just
something vs allows? And if you would have a work around..
Thanks! 7 5489
> I am probably asking for something which was discussed several times, but all my researches were unsucessfull.
If you look at this code (simplified part of my project):
--------------- template< int dimension > struct Test { template< class A > struct assignement { template< int I > struct recurse { enum { Counter = I + 1 }; static inline void assign( void* v, const A& a ) { recurse<Counter >::assign( v, a ); } };
template<> struct recurse<dimensi on> { enum { Counter = dimension + 1 }; static inline void assign( void*, const A& ) { } };
static inline void assign( void* v, const A& a ) { recurse<0>::ass ign( v, a ); } }; };
---------
This code compiles fine with vs2005, but not with g++, which gives me errors on my specialization template<> struct recurse<dimensi on>:
error: invalid explicit specialization before '>' token error: explicit specialization in non-namespace scope `struct Test<dimension> ::assignement<A >' error: enclosing class templates are not explicitly specialized error: template parameters not used in partial specialization: error: `A'
Even though i thought this was completely correct, i tried to put it outside the class definition, but couldnt get it working.
So i am wondering if what i am doing is actually proper c++, or just something vs allows? And if you would have a work around..
MSVC is wrong in this case and g++ correct. Explicit template specialization
is forbidden for nested classes.
As partial template specialization is not forbidden, you get around quite
comfortable. I did not test it, if it is not working, I have to dig in my
code:
template< int dimension > struct Test
{
template< class A > struct assignement
{
template< int I, typename T = void > struct recurse
{
enum { Counter = I + 1 };
static inline void assign( void* v, const A& a )
{
recurse<Counter >::assign( v, a );
}
};
template< typename T > struct recurse<dimensi on, T>
{
enum { Counter = dimension + 1 };
static inline void assign( void*, const A& )
{
}
};
static inline void assign( void* v, const A& a )
{
recurse<0>::ass ign( v, a );
}
};
};
Thanks Patrick,
I didn't know explicit template specialization is forbidden for nested
classes. Your change works indeed fine, except when i put this part
back into the main code, it looks infinitely (my terminator is not
used).
/kUfa
looks=loops, sorry for the typo
> Thanks Patrick, I didn't know explicit template specialization is forbidden for nested classes. Your change works indeed fine, except when i put this part back into the main code, it looks infinitely (my terminator is not used).
Hello Kufa,
I can confirm the infinitive loop for VS2003 and gcc. It looks like a bug to
me.
If you can iterate backwards, you can partial specialize to 0, what works
fine.
Patrick
Yes indeed! Thanks alot Patrick!
"Patrick Kowalzick" <pa************ ***@mapandguide .de> skrev i
meddelandet news:ne******** ************@pr oxy.mapandguide .de... This code compiles fine with vs2005, but not with g++, which gives me errors on my specialization template<> struct recurse<dimensi on>:
MSVC is wrong in this case and g++ correct. Explicit template specialization is forbidden for nested classes.
It's an MS extension, from way back. If you add the Disable Language
Extensions option to the compile, the code will be rejected.
Bo Persson This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Agent Mulder |
last post by:
Hi group,
I have a problem with partial template specialization. In the code
below I have a template struct Music with one method, play(),
and three kinds of music, Jazz, Funk and Bach. When I specialize
Music<Bach>, I expect that the original play() method is available
in the specialization, but it is not. How can I fix this?
-X
|
by: Enos Meroka |
last post by:
Hallo,
I am a student doing my project in the university.. I have been trying
to compile the program using HP -UX aCC compiler, however I keep on
getting the following errors.
=================================================================
Error 19: "CORBAManagerMessages.h", line 4 # Unexpected 'std'.
using std::string;
^^^
|
by: Nicolas Fleury |
last post by:
Hi everyone, I would to know what do you think of this PEP. Any comment
welcomed (even about English mistakes).
PEP: XXX
Title: Specialization Syntax
Version: $Revision: 1.10 $
Last-Modified: $Date: 2003/09/22 04:51:49 $
Author: Nicolas Fleury <nidoizo at gmail.com>
Status: Draft
Type: Standards Track
|
by: Kai-Uwe Bux |
last post by:
Hi folks,
I observed something that puzzles me. When I do
namespace xxx { using std::swap; }
it appears that xxx::swap and std::swap are not strictly equivalent. In
particular, I think that my implementation will only choose the partial
specialization for std::vector when std::swap is used.
|
by: Ferdi Smit |
last post by:
I've never understood the rationale of allowing partial, but not
explicit specialization for classes at non-namespace scope. Ie.:
struct A {
template <typename T1, typename T2>
struct B {};
// this is not allowed:
template <>
struct B<int, float> {};
| |
by: Marcin Kalicinski |
last post by:
Is it well formed C++ to define free swap function for my custom container
in std namespace?
cheers,
Marcin
|
by: Noah Roberts |
last post by:
template < typename T >
std::istream & operator >(std::istream & in, std::pair<T,T& p)
{
in >p.first >p.second;
return in;
}
....
std::istream_iterator< std::pair<size_type, size_type
|
by: flopbucket |
last post by:
Hi,
I want to provide a specialization of a class for any type T that is a
std::map.
template<typename T>
class Foo
{
// ...
};
|
by: Knut Stolze |
last post by:
Hi,
Let's assume I have a namespace that contains a class definition. Now I would like to add a template specialization for std::numeric_limits for the new class. I want to have this specialization inside the scope of the namespace. Is there any way how I can "leave" or "unnest" the namespace NS so that I can have the declaration inside the "std" namespace instead of NS::std.
#include <iostream>
#include <limits>
namespace NS {
...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |