473,387 Members | 1,749 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,387 software developers and data experts.

set<const int> - does not compile

This code does not compile on gcc 3.4.4. Should it?

Thanks for your help,

Chris

//================
#include <set>

int main()
{
std::set<const int> s;

s.insert(3);

return 0;
}

//================

[cstankevitz@maggie temp]$ g++ --version
g++ (GCC) 3.4.4 20050721 (Red Hat 3.4.4-2)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is
NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.
[cstankevitz@maggie temp]$ g++ temp.cpp
/usr/lib/gcc/x86_64-redhat-linux/3.4.4/../../../../include/c++/3.4.4/ext/new_all
ocator.h: In instantiation of `__gnu_cxx::new_allocator<const int>':
/usr/lib/gcc/x86_64-redhat-linux/3.4.4/../../../../include/c++/3.4.4/bits/alloca
tor.h:81: instantiated from `std::allocator<const int>'
/usr/lib/gcc/x86_64-redhat-linux/3.4.4/../../../../include/c++/3.4.4/bits/stl_tr
ee.h:329: instantiated from `std::_Rb_tree<const int, const int,
std::_Identit
y<const int>, std::less<const int>, std::allocator<const int> >'
/usr/lib/gcc/x86_64-redhat-linux/3.4.4/../../../../include/c++/3.4.4/bits/stl_se
t.h:127: instantiated from `std::set<const int, std::less<const int>,
std::all
ocator<const int> >'
temp.cpp:5: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/3.4.4/../../../../include/c++/3.4.4/ext/new_all
ocator.h:75: error: `const _Tp*
__gnu_cxx::new_allocator<_Tp>::address(const _Tp
&) const [with _Tp = const int]' and `_Tp*
__gnu_cxx::new_allocator<_Tp>::addres
s(_Tp&) const [with _Tp = const int]' cannot be overloaded
/usr/lib/gcc/x86_64-redhat-linux/3.4.4/../../../../include/c++/3.4.4/bits/stl_fu
nction.h: In instantiation of `std::_Identity<const int>':
/usr/lib/gcc/x86_64-redhat-linux/3.4.4/../../../../include/c++/3.4.4/bits/stl_tr
ee.h:871: instantiated from `std::pair<typename std::_Rb_tree<_Key,
_Val, _Key
OfValue, _Compare, _Alloc>::iterator, bool> std::_Rb_tree<_Key, _Val,
_KeyOfValu
e, _Compare, _Alloc>::insert_unique(const _Val&) [with _Key = const
int, _Val =
const int, _KeyOfValue = std::_Identity<const int>, _Compare =
std::less<const i
nt>, _Alloc = std::allocator<const int>]'
/usr/lib/gcc/x86_64-redhat-linux/3.4.4/../../../../include/c++/3.4.4/bits/stl_se
t.h:314: instantiated from `std::pair<typename std::_Rb_tree<_Key,
_Key, std::
_Identity<_Key>, _Compare, _Alloc>::const_iterator, bool>
std::set<_Key, _Compar
e, _Alloc>::insert(const _Key&) [with _Key = const int, _Compare =
std::less<con
st int>, _Alloc = std::allocator<const int>]'
temp.cpp:7: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/3.4.4/../../../../include/c++/3.4.4/bits/stl_fu
nction.h:538: error: `const _Tp& std::_Identity<_Tp>::operator()(const
_Tp&) con
st [with _Tp = const int]' and `_Tp&
std::_Identity<_Tp>::operator()(_Tp&) const
[with _Tp = const int]' cannot be overloaded
/usr/lib/gcc/x86_64-redhat-linux/3.4.4/../../../../include/c++/3.4.4/bits/stl_co
nstruct.h: In function `void std::_Construct(_T1*, const _T2&) [with
_T1 = const
int, _T2 = int]':
/usr/lib/gcc/x86_64-redhat-linux/3.4.4/../../../../include/c++/3.4.4/bits/stl_tr
ee.h:367: instantiated from `std::_Rb_tree_node<_Val>*
std::_Rb_tree<_Key, _Va
l, _KeyOfValue, _Compare, _Alloc>::_M_create_node(const _Val&) [with
_Key = cons
t int, _Val = const int, _KeyOfValue = std::_Identity<const int>,
_Compare = std
::less<const int>, _Alloc = std::allocator<const int>]'
/usr/lib/gcc/x86_64-redhat-linux/3.4.4/../../../../include/c++/3.4.4/bits/stl_tr
ee.h:783: instantiated from `typename std::_Rb_tree<_Key, _Val,
_KeyOfValue, _
Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue,
_Compare, _All
oc>::_M_insert(std::_Rb_tree_node_base*, std::_Rb_tree_node_base*,
const _Val&)
[with _Key = const int, _Val = const int, _KeyOfValue =
std::_Identity<const int
, _Compare = std::less<const int>, _Alloc = std::allocator<const int>]'

/usr/lib/gcc/x86_64-redhat-linux/3.4.4/../../../../include/c++/3.4.4/bits/stl_tr
ee.h:877: instantiated from `std::pair<typename std::_Rb_tree<_Key,
_Val, _Key
OfValue, _Compare, _Alloc>::iterator, bool> std::_Rb_tree<_Key, _Val,
_KeyOfValu
e, _Compare, _Alloc>::insert_unique(const _Val&) [with _Key = const
int, _Val =
const int, _KeyOfValue = std::_Identity<const int>, _Compare =
std::less<const i
nt>, _Alloc = std::allocator<const int>]'
/usr/lib/gcc/x86_64-redhat-linux/3.4.4/../../../../include/c++/3.4.4/bits/stl_se
t.h:314: instantiated from `std::pair<typename std::_Rb_tree<_Key,
_Key, std::
_Identity<_Key>, _Compare, _Alloc>::const_iterator, bool>
std::set<_Key, _Compar
e, _Alloc>::insert(const _Key&) [with _Key = const int, _Compare =
std::less<con
st int>, _Alloc = std::allocator<const int>]'
temp.cpp:7: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/3.4.4/../../../../include/c++/3.4.4/bits/stl_co
nstruct.h:81: error: invalid static_cast from type `const int*' to type
`void*'

Dec 9 '05 #1
4 2733

ch*************@yahoo.com wrote:
This code does not compile on gcc 3.4.4. Should it?
Since contents of an stl container must be assignable I wouldn't think
so.
std::set<const int> s;


Dec 9 '05 #2
Thanks for your reply.

Do you know what is the rationale behind the requirement "the contents
of an stl container must be assignable"?

I can understand this requirement for vectors (which copy elements as
they grow), but not for other containers like the linked list and set.
I'm suprised I never heard this requirement. I can't find any
reference to it in Stroustrup's or Josuttis's books.

Thanks for your help,

Chris

Dec 9 '05 #3
I see it now:

Josuttis section 5.10.1:
An element must be assignable by the assignment operator.

Thanks,

Chris

Dec 9 '05 #4

ch*************@yahoo.com wrote:
Thanks for your reply.

Do you know what is the rationale behind the requirement "the contents
of an stl container must be assignable"?


Well, many operations on a list assign values. Creating a list that
doesn't would require a special case in which many of std::list's
operations would be invalid and even more would need drastic changes.
If you really need this type of thing you'll have to create it in a
container of your own design.

Dec 9 '05 #5

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

Similar topics

4
by: Luca | last post by:
I have the need of a container of integers showing both the characteristics of an associative container (all integer elements different from each other) and the FIFO behaviour. Do you know if...
5
by: Peter Jansson | last post by:
Hello, I have the following code: std::map<int,std::set<std::string> > k; k="1234567890"; k="2345678901"; //... std::set<std::string> myMethod(std::map<int,std::set<std::string> > k)...
5
by: pmatos | last post by:
Hi all, I have a vector of vector of ints, I could use C approach by using int but I think C++ vector<vector<int> > would be easier to manage. So I have a function which creates and initializes...
10
by: Piotr | last post by:
I have a class 'Statistics' which has a private attribute ' vector<int>* _x;' And in the destructor of the Statistics, I have this code to free the memory: Statistics::~Statistics() { if...
4
by: Stuart Moore | last post by:
Hi, I'm quite new to templates and I seem to be getting myself messed up. I want to write a function that takes a map<T, int> and a set<T>, iterates over the set, and increments the corresponding...
2
by: per9000 | last post by:
Hi, *background* I want a class containing an int (a list of sets of integer). This should be hidden for the user and he/she should be able to insert his/her favourite data structure so to be a...
8
by: per9000 | last post by:
Hi, I wanted to test to compile an application I build for .NET 2.0 in with the 1.1 C# compiler. I encountered difficulties since I had a List<myClass>. I found a list of what is new in .NET 2.0...
1
by: Monty | last post by:
I have a Usercontrol with a public property List<intLinks List <intLinks= new List<int>(); public List<intLinkLabels { get { return Links; } set { Links = value; } }
6
by: chandramohanp | last post by:
Hi I am trying to modify class instance members using reflection. I am having problem when trying to add/remove/display elements related to List<int> member. Following is the code. class...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...

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.