473,398 Members | 2,368 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,398 software developers and data experts.

problem with template template parameter.

I'm playing with template template parameters. I'm not
sure what I'm doing wrong here. Could someone with better
template template experience give me a hand?

Code and Comeau online error below.
#include <vector>

template<template<typenameclass C, typename T>
T* iterator_cast(typename C<T>::iterator it)
{
return &*it;
}

int* cast_tester(std::vector<int>& c)
{
return iterator_cast(c.begin()); // line 12
}
Comeau online gives me the following error (G++ 3.4.4 gives a similar errr):

"ComeauTest.c", line 12: error: no instance of function template
"iterator_cast"
matches the argument list
The argument types that you used are: (std::vector<int,
std::allocator<int>>::iterator)
return iterator_cast(c.begin());
Jul 27 '06 #1
4 2920
"red floyd" <no*****@here.dudewrote...
I'm playing with template template parameters. I'm not
sure what I'm doing wrong here. Could someone with better
template template experience give me a hand?

Code and Comeau online error below.
#include <vector>

template<template<typenameclass C, typename T>
T* iterator_cast(typename C<T>::iterator it)
{
return &*it;
}

int* cast_tester(std::vector<int>& c)
{
return iterator_cast(c.begin()); // line 12
}
Comeau online gives me the following error (G++ 3.4.4 gives a similar
errr):

"ComeauTest.c", line 12: error: no instance of function template
"iterator_cast"
matches the argument list
The argument types that you used are: (std::vector<int,
std::allocator<int>>::iterator)
return iterator_cast(c.begin());
Most likely you've run into non-deducible context. I don't think
that 'T' can be deduced from a member of C<T>.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 27 '06 #2
Victor Bazarov wrote:
"red floyd" <no*****@here.dudewrote...
>>

#include <vector>

template<template<typenameclass C, typename T>
T* iterator_cast(typename C<T>::iterator it)
{
return &*it;
}

int* cast_tester(std::vector<int>& c)
{
return iterator_cast(c.begin()); // line 12
}

Most likely you've run into non-deducible context. I don't think
that 'T' can be deduced from a member of C<T>.
By the way, the rationale behind this function is to make it obvious in
the code when we are converting an iterator to a pointer.
Given the potential non-deducible context, , I've gotten rid of the
template template, and went with a "simple" template.

#include <vector>
#include <iterator>

template <typename Iterator>
typename std::iterator_traits<Iterator>::pointer_type
iterator_cast(Iterator iter)
{
return &*iter;
}
int* cast_tester(std::vector<int>& c)
{
return iterator_cast(c.begin());
}
Comeau online still errors:
Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++

"ComeauTest.c", line 13: error: no instance of function template
"iterator_cast"
matches the argument list
The argument types that you used are: (std::vector<int,
std::allocator<int>>::iterator)
return iterator_cast(c.begin());
^

1 error detected in the compilation of "ComeauTest.c".
Jul 27 '06 #3
red floyd wrote:
Victor Bazarov wrote:
>"red floyd" <no*****@here.dudewrote...
>>>

#include <vector>

template<template<typenameclass C, typename T>
T* iterator_cast(typename C<T>::iterator it)
{
return &*it;
}

int* cast_tester(std::vector<int>& c)
{
return iterator_cast(c.begin()); // line 12
}

Most likely you've run into non-deducible context. I don't think
that 'T' can be deduced from a member of C<T>.

By the way, the rationale behind this function is to make it obvious in
the code when we are converting an iterator to a pointer.
Given the potential non-deducible context, , I've gotten rid of the
template template, and went with a "simple" template.

#include <vector>
#include <iterator>

template <typename Iterator>
typename std::iterator_traits<Iterator>::pointer_type
iterator_cast(Iterator iter)
{
return &*iter;
}
int* cast_tester(std::vector<int>& c)
{
return iterator_cast(c.begin());
}
Comeau online still errors:
Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++

"ComeauTest.c", line 13: error: no instance of function template
"iterator_cast"
matches the argument list
The argument types that you used are: (std::vector<int,
std::allocator<int>>::iterator)
return iterator_cast(c.begin());
^

1 error detected in the compilation of "ComeauTest.c".
Never mind. Found the error. I shouldn't have used "pointer_type", but
only "pointer" as the return type.

Jul 27 '06 #4
"red floyd" <no*****@here.dudewrote...
[..]
Given the potential non-deducible context, , I've gotten rid of the
template template, and went with a "simple" template.

#include <vector>
#include <iterator>

template <typename Iterator>
typename std::iterator_traits<Iterator>::pointer_type
iterator_cast(Iterator iter)
{
return &*iter;
}
int* cast_tester(std::vector<int>& c)
{
return iterator_cast(c.begin());
}
Comeau online still errors:
Comeau C/C++ 4.3.3 (Aug 6 2003 15:13:37) for ONLINE_EVALUATION_BETA1
Copyright 1988-2003 Comeau Computing. All rights reserved.
MODE:strict errors C++

"ComeauTest.c", line 13: error: no instance of function template
"iterator_cast"
matches the argument list
The argument types that you used are: (std::vector<int,
std::allocator<int>>::iterator)
return iterator_cast(c.begin());
^

1 error detected in the compilation of "ComeauTest.c".
Are you sure that 'pointer_type' is actually defined for the iterator_traits
instantiated on the vector's iterator?

It seems that you're running into SFINAE -- if the function cannot be
created
(instantiated) becuase of non-existent return value type, no function exists
to be found in the 'return' expression.

V

P.S. Sorry for overquoting, everybody.
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Jul 27 '06 #5

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

Similar topics

0
by: tyousaf | last post by:
Hi i am new to mysql and mysql++, i have installed mysql server, it is running fine. i also installed "mysql++-1.7.9gcc3.2-2.i386.rpm" (i have gcc 3.3) , first of all as the readme file says to do...
0
by: David Furey | last post by:
Hi, I am using the XSLT document to filter records from an XML document The XSL is shown below: I have a parameter named "search-for" that is used to bring back a list of Vendor Names that...
7
by: Hendrik Schober | last post by:
Hi, I have a problem, that boils down to the following code: #include <iostream> #include <typeinfo> class Test1 {}; class Test2 {}; class Test3 {};
11
by: Alexander Stippler | last post by:
Hi, I have a little problem to design some template classes in a realizable way. I have some Container classes and some Proxy classes (proxies for elements). Looks like this: // P is the...
7
by: Lionel B | last post by:
Greetings. The following code compiles ok and does what I'd expect it to do: ---------- START CODE ---------- // test.cpp
9
by: Prasad | last post by:
HI, I am a beginner in VC++.. I am trying to write a Win32 console application in visual studio.. I am using following header files.. #include <STRING> using namespace std; #include...
2
by: kalki70 | last post by:
Hi, I'm working with templates, but I have a syntax problem I don't know how to fix. I built a small example, so maybe you can tell me how to write correctly this code. I have 2 files :...
4
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which -...
2
by: aitrob | last post by:
Hi, I have a problem concerning templates/inheritance. I have a code that compiles fine with g++ 4.0.1 (Apple version), but gives a lot of errors with Intel C++ 10.1 (Mac OS X). I'm not sure if...
6
by: Gaijinco | last post by:
I'm trying to do a template class Node. My node.hpp is: #ifndef _NODE_HPP_ #define _NODE_HPP_ namespace com { namespace mnya { namespace carlos { template <typename T>
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
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,...
0
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...
0
tracyyun
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...
0
isladogs
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...

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.