473,581 Members | 2,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Some problems with std::vector and nested templates

Hi

I'm trying to do the following.

#include <vector>
#include <boost/thread/mutex.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/tuple/tuple.hpp>

class {
boost::mutex m_lock;
std::vector<boo st::tuple<uint3 2_t, boost::shared_p tr<T >
m_vector;

template <class Tboost::shared_ ptr<Tlist::<T>g etitem(uint32_t id)
{
boost::mutex::s coped_lock lock(m_lock);

std::vector< boost::tuple<ui nt32_t, boost::shared_p tr<T
>::iterator pos =
find_if(m_vecto r.begin(), m_vector.end(), compare_list<T> (id),
m_vector.begin( ));

if (pos != m_vector.end())
return *pos;

return boost::shared_p tr(NULL);
};

but I get the following error
error: expected ';' before 'pos'

I don't understand why I'm getting this error because the definition
of std::vector works, it's just the iterator statement that doesn't.

Jun 17 '07 #1
13 2947
jubelbrus wrote:
Hi

I'm trying to do the following.

#include <vector>
#include <boost/thread/mutex.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/tuple/tuple.hpp>

class {
boost::mutex m_lock;
std::vector<boo st::tuple<uint3 2_t, boost::shared_p tr<T >
m_vector;
I'm assuming uint32_t might be typedefed somewhere.
What's T? This is not a template?
template <class Tboost::shared_ ptr<Tlist::<T>g etitem(uint32_t id)
huh?
template <class T>
boost::shared_p tr<T>
list<T>::getite m(uint32_t id)
?
What's list?
{
boost::mutex::s coped_lock lock(m_lock);

std::vector< boost::tuple<ui nt32_t, boost::shared_p tr<T
>>::iterator pos =
find_if(m_vecto r.begin(), m_vector.end(), compare_list<T> (id),
m_vector.begin( ));
typename std::vector<boo st::tuple<uint3 2_t, boost::shared_p tr<T
>::iterator pos = find_if(...)
You need typename here, because vector< ... is dependent on T.
if (pos != m_vector.end())
return *pos;
*pos is a tuple, not a shared_ptr
return boost::shared_p tr(NULL);
};

but I get the following error
error: expected ';' before 'pos'

I don't understand why I'm getting this error because the definition
of std::vector works, it's just the iterator statement that doesn't.
--
rbh
Jun 17 '07 #2
Sorry about the misspellings...

This is what I'm trying to do:
Write a template class that stores a list of boost::shared_p tr<Twith
a index and is thread safe, where T would be that template <class T>
stuff..

I got the getitem function compiling by using typename, tanks.. but
I've discovered some compile problems with my insert code.

#include <stdint.h>
#include <vector>
#include <boost/thread/mutex.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/tuple/tuple.hpp>

template <class T>
class list{
boost::mutex m_lock;
std::vector<boo st::tuple<uint3 2_t, boost::shared_p tr<T >
m_vector;

uint32_t m_nextid;

uint32_t insert(boost::s hared_ptr<T>);
}

template <class T>
uint32_t list<T>::insert (boost::shared_ ptr<T>)
{
typename boost::tuples:: tuple<uint32_t, boost::shared_p tr<T
add_item(m_next id, item);
typename std::vector<boo st::tuple<uint3 2_t, boost::shared_p tr<T
m_vector;
boost::mutex::s coped_lock lock(m_lock);

m_vector.insert ( add_item );
return m_nextid++;

};

I get the following error:
list.h: In member function 'uint32_t
stdtools::list< T>::insert(boos t::shared_ptr<T >) [with T = int]':
tester_a.cpp:10 : instantiated from here
list.h:90: error: no matching function for call to
'std::vector<bo ost::tuples::tu ple<uint32_t, boost::shared_p tr<int>,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type>,
std::allocator< boost::tuples:: tuple<uint32_t, boost::shared_p tr<int>,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type
>::insert(boost ::tuples::tuple <uint32_t, boost::shared_p tr<int>,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type>&)'
/usr/include/c++/4.0.0/bits/vector.tcc:93: note: candidates are:
typename std::vector<_Tp , _Alloc>::iterat or std::vector<_Tp ,
_Alloc>::insert (__gnu_cxx::__n ormal_iterator< typename _Alloc::pointer ,
std::vector<_Tp , _Alloc, const _Tp&) [with _Tp =
boost::tuples:: tuple<uint32_t, boost::shared_p tr<int>,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type>, _Alloc =
std::allocator< boost::tuples:: tuple<uint32_t, boost::shared_p tr<int>,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type]
/usr/include/c++/4.0.0/bits/stl_vector.h:65 7: note:
void std::vector<_Tp ,
_Alloc>::insert (__gnu_cxx::__n ormal_iterator< typename _Alloc::pointer ,
std::vector<_Tp , _Alloc, size_t, const _Tp&) [with _Tp =
boost::tuples:: tuple<uint32_t, boost::shared_p tr<int>,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type>, _Alloc =
std::allocator< boost::tuples:: tuple<uint32_t, boost::shared_p tr<int>,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type]

Anybody??

Jun 17 '07 #3
jubelbrus wrote:
Sorry about the misspellings...

This is what I'm trying to do:
Write a template class that stores a list of boost::shared_p tr<Twith
a index and is thread safe, where T would be that template <class T>
stuff..

I got the getitem function compiling by using typename, tanks.. but
I've discovered some compile problems with my insert code.

#include <stdint.h>
#include <vector>
#include <boost/thread/mutex.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/tuple/tuple.hpp>

template <class T>
class list{
boost::mutex m_lock;
std::vector<boo st::tuple<uint3 2_t, boost::shared_p tr<T >
m_vector;

uint32_t m_nextid;

uint32_t insert(boost::s hared_ptr<T>);
}

template <class T>
uint32_t list<T>::insert (boost::shared_ ptr<T>)
{
typename boost::tuples:: tuple<uint32_t, boost::shared_p tr<T
add_item(m_next id, item);
typename std::vector<boo st::tuple<uint3 2_t, boost::shared_p tr<T
>m_vector;

boost::mutex::s coped_lock lock(m_lock);

m_vector.insert ( add_item );
Perhaps you mean

m_vector.push_b ack( add_item );

There is no method of vector called insert that takes a single argument.

john
Jun 17 '07 #4
On 17 Jun, 17:49, John Harrison <john_androni.. .@hotmail.comwr ote:
jubelbrus wrote:
Sorry about the misspellings...
This is what I'm trying to do:
Write a template class that stores a list of boost::shared_p tr<Twith
a index and is thread safe, where T would be that template <class T>
stuff..
I got the getitem function compiling by using typename, tanks.. but
I've discovered some compile problems with my insert code.
#include <stdint.h>
#include <vector>
#include <boost/thread/mutex.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/tuple/tuple.hpp>
template <class T>
class list{
boost::mutex m_lock;
std::vector<boo st::tuple<uint3 2_t, boost::shared_p tr<T >
m_vector;
uint32_t m_nextid;
uint32_t insert(boost::s hared_ptr<T>);
}
template <class T>
uint32_t list<T>::insert (boost::shared_ ptr<T>)
{
typename boost::tuples:: tuple<uint32_t, boost::shared_p tr<T
add_item(m_next id, item);
typename std::vector<boo st::tuple<uint3 2_t, boost::shared_p tr<T
m_vector;
boost::mutex::s coped_lock lock(m_lock);
m_vector.insert ( add_item );

Perhaps you mean

m_vector.push_b ack( add_item );

There is no method of vector called insert that takes a single argument.

john
oh... :)

thanks

Jun 17 '07 #5
jubelbrus wrote:
Sorry about the misspellings...

This is what I'm trying to do:
Write a template class that stores a list of boost::shared_p tr<Twith
a index and is thread safe, where T would be that template <class T>
stuff..

I got the getitem function compiling by using typename, tanks.. but
I've discovered some compile problems with my insert code.

#include <stdint.h>
#include <vector>
#include <boost/thread/mutex.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/tuple/tuple.hpp>

template <class T>
class list{
boost::mutex m_lock;
std::vector<boo st::tuple<uint3 2_t, boost::shared_p tr<T >
m_vector;

uint32_t m_nextid;

uint32_t insert(boost::s hared_ptr<T>);
}

template <class T>
uint32_t list<T>::insert (boost::shared_ ptr<T>)
{
typename boost::tuples:: tuple<uint32_t, boost::shared_p tr<T
add_item(m_next id, item);
There should be no typename here.
typename std::vector<boo st::tuple<uint3 2_t, boost::shared_p tr<T
>m_vector;
nor here.

typename are needed in:
T::something
or
someclass<T>::s omething
To put it very short.

This is because the compiler cannot possibly know what something is. The
first is obvious. The second:

template <class T>
class someclass {
public:
typedef T something;
};

int p;

template <class T>
void foo() {
someclass<T>::s omething * p; /*Missing typename and definition of local p
or multiplication? Standard says multiplication */
}

template <>
class someclass<int{
public:
int something;
};

int someclass<int>: :something = 3;

int main() {
p = 42;
foo<int>();
}
boost::mutex::s coped_lock lock(m_lock);

m_vector.insert ( add_item );
return m_nextid++;

};

I get the following error:
list.h: In member function 'uint32_t
stdtools::list< T>::insert(boos t::shared_ptr<T >) [with T = int]':
tester_a.cpp:10 : instantiated from here
list.h:90: error: no matching function for call to
// beginning
'std::vector<bo ost::tuples::tu ple<uint32_t, boost::shared_p tr<int>,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type>,
std::allocator< boost::tuples:: tuple<uint32_t, boost::shared_p tr<int>,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type
>>::insert(boos t::tuples::tupl e<uint32_t, boost::shared_p tr<int>,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type>&)'
//end

Shorter:
std::vector<... >::insert(tuple <...>)
/usr/include/c++/4.0.0/bits/vector.tcc:93: note: candidates are:
//beginning
typename std::vector<_Tp , _Alloc>::iterat or std::vector<_Tp ,
_Alloc>::insert (__gnu_cxx::__n ormal_iterator< typename _Alloc::pointer ,
std::vector<_Tp , _Alloc, const _Tp&) [with _Tp =
boost::tuples:: tuple<uint32_t, boost::shared_p tr<int>,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type>, _Alloc =
std::allocator< boost::tuples:: tuple<uint32_t, boost::shared_p tr<int>,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type]
//end
shorter:
std::vector<... >::insert(std:: vector<...>::it erator, const tuple<...>&)
/usr/include/c++/4.0.0/bits/stl_vector.h:65 7: note:
void std::vector<_Tp ,
//beginning
_Alloc>::insert (__gnu_cxx::__n ormal_iterator< typename _Alloc::pointer ,
std::vector<_Tp , _Alloc, size_t, const _Tp&) [with _Tp =
boost::tuples:: tuple<uint32_t, boost::shared_p tr<int>,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type>, _Alloc =
std::allocator< boost::tuples:: tuple<uint32_t, boost::shared_p tr<int>,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type,
boost::tuples:: null_type, boost::tuples:: null_type]
//end

shorter:
std::vector<... >::insert(std:: vector<...>::it erator, size_t, const
tuple<...>&)

Read the messages. They're long and hairy, but it's possible. Matching
parens is a good start.

--
rbh
Jun 17 '07 #6
On Sun, 17 Jun 2007 15:22:52 -0000, jubelbrus wrote:
>I get the following error:
list.h: In member function 'uint32_t
stdtools::list <T>::insert(boo st::shared_ptr< T>) [with T = int]':
tester_a.cpp:1 0: instantiated from here
list.h:90: error: no matching function for call to
'std::vector<b oost::tuples::t uple<uint32_t, boost::shared_p tr<int>,
boost::tuples: :null_type, boost::tuples:: null_type,
boost::tuples: :null_type, boost::tuples:: null_type,
boost::tuples: :null_type, boost::tuples:: null_type,
boost::tuples: :null_type, boost::tuples:: null_type>,
[snipped template jumble]

Why don't you ask Boost when you've got a Boost problem?
http://www.boost.org/more/mailing_lists.htm#users
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Jun 17 '07 #7
>Perhaps you mean
>>
m_vector.push_b ack( add_item );

There is no method of vector called insert that takes a single argument.

john

oh... :)

thanks
Those super long error messages make you think there must be something
really significant wrong with your code. But sometimes it's just the
obvious stuff.

john
Jun 17 '07 #8
On Sun, 17 Jun 2007 16:00:40 GMT, John Harrison wrote:
>Those super long error messages make you think there must be something
really significant wrong with your code. But sometimes it's just the
obvious stuff.
Obviously, there is 'something really significant wrong' with Boost.
--
Roland Pibinger
"The best software is simple, elegant, and full of drama" - Grady Booch
Jun 17 '07 #9
In article <46************ **@news.utanet. at>, rp*****@yahoo.c om says...
On Sun, 17 Jun 2007 16:00:40 GMT, John Harrison wrote:
Those super long error messages make you think there must be something
really significant wrong with your code. But sometimes it's just the
obvious stuff.

Obviously, there is 'something really significant wrong' with Boost.
Hardly -- you can get the same sort of problems without using Boost. The
problem is sufficiently widespread that Leor Zolman has put quite a bit
of work into stlfilt, to try to make error messages more readable. As I
understand it, lousy error messages from templated code also provided
the motivation for the work that led to Concepts.

--
Later,
Jerry.

The universe is a figment of its own imagination.
Jun 17 '07 #10

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

Similar topics

5
3388
by: bartek d | last post by:
Hello, Regarding my previous question about a class which is used to store a variable type vector. I tried to be more elaborate on the code. I'd be grateful for your suggestions. Am I going in the wrong direction with the implementation? I'm asking this because I don't have much experience with C++. Thanks in advance. The main problem...
27
5938
by: Jason Heyes | last post by:
To my understanding, std::vector does not use reference counting to avoid the overhead of copying and initialisation. Where can I get a reference counted implementation of std::vector? Thanks.
5
1768
by: Eric Lilja | last post by:
Hello, consider this complete program (sorry, it's not minimal but I hope it's readable at least): #include <algorithm> #include <iostream> #include <vector> class Row { public:
20
17776
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; std::vector<double>::size_type size = src.size(); dest.reserve(size); for (std::vector<int>::size_type i = 0;
17
3341
by: Michael Hopkins | last post by:
Hi all I want to create a std::vector that goes from 1 to n instead of 0 to n-1. The only change this will have is in loops and when the vector returns positions of elements etc. I am calling this uovec at the moment (for Unit-Offset VECtor). I want the class to respond correctly to all usage of STL containers and algorithms so that it is...
32
69666
by: zl2k | last post by:
hi, c++ user Suppose I constructed a large array and put it in the std::vector in a function and now I want to return it back to where the function is called. I can do like this: std::vector<int> fun(){ //build the vector v; return v; }
56
5740
by: Peter Olcott | last post by:
I am trying to refer to the same std::vector in a class by two different names, I tried a union, and I tried a reference, I can't seem to get the syntax right. Can anyone please help? Thanks
82
3963
by: Peter Olcott | last post by:
I need std::vector like capability for several custom classes. I already discussed this extensively in the thread named ArrayList without Boxing and Unboxing. The solution was to simply create non-generic (non C++ template) std::vector like capability for each of these custom classes. (Solution must work in Visual Studio 2002). Since I have...
7
2526
by: Thomas | last post by:
I am compiling with g++ the fol. class: template<typename E> class C_vector_ : public std::vector<E> { private:
0
8304
jinu1996
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...
1
7899
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...
0
8175
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 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...
0
6553
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5674
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5364
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3805
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3827
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2301
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 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.