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

std::tr1::array iterator types

Hello,

The following code compiles (gcc/linux/gnu platform)
//////////////////////
#include <tr1/array>

int main()
{
std::tr1::array<int, 7a;
std::tr1::array<int, 6>::iterator i = a.begin()+1;

return 0;
}
/////////////////////

That it compiles is "logical" if you consider that what remains after
the first element of a an array of length 7, is an array of length 6.

It is also "illogical" if you consider that the iterator returned by
a.begin() is of type std::tr1::array<int, 7>::iterator, and merely
adding 1 to it should cause it to change its type.

Unless, of course, all iterators of type
std::tr1::array<int, X>::iterator are the same for all X.

Question: is it indeed guaranteed in the standard that all types
std::tr1::array<int, X>::iterator are identical for all X ?

Thanks in advance,
Fokko Beekhof
Apr 7 '08 #1
1 2404
Fokko Beekhof wrote:
Hello,

The following code compiles (gcc/linux/gnu platform)
//////////////////////
#include <tr1/array>

int main()
{
std::tr1::array<int, 7a;
std::tr1::array<int, 6>::iterator i = a.begin()+1;

return 0;
}
/////////////////////

That it compiles is "logical" if you consider that what remains
after the first element of a an array of length 7, is an array of
length 6.

It is also "illogical" if you consider that the iterator returned by
a.begin() is of type std::tr1::array<int, 7>::iterator, and merely
adding 1 to it should cause it to change its type.

Unless, of course, all iterators of type
std::tr1::array<int, X>::iterator are the same for all X.

Question: is it indeed guaranteed in the standard that all types
std::tr1::array<int, X>::iterator are identical for all X ?
No, there are no such guarantees.

That it happens to work is probably an effect of the requirements for
iterator::value_type, which of course must be int for all
array<int,X>.
Bo Persson
Apr 7 '08 #2

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

Similar topics

8
by: Hagen | last post by:
Hi, I have a question that you probably shouldnĀ“t worry about since the compiler cares for it, but anyways: When you run your compiler with optimization turned on (eg. g++ with -Ox flag) and...
16
by: Frederick Gotham | last post by:
Inspired by page 219 of Nicolai M. Josuttis's book, I set out to write a class for an intrinsic array which would behave, to as far an extent as possible, like a container. Also though, I wanted no...
2
by: kgeorge2 | last post by:
A library which i use, has an array class class LibArray { public: LibArray():_array(NULL),_len(0); LibArray(int n, float val):_array( new float),_len(n){} /** more complete definition...
13
by: stephen b | last post by:
(apologies for cross posting from the moderated group..i'm sure you understand) Hello, I'm passing an array into a Constructor and hoping to use it as a pointer and store it as a class member...
8
by: Spoon | last post by:
Hello, Could someone explain why the following code is illegal? (I'm trying to use a list of (C-style) arrays.) #include <list> typedef std::list < int foo_t; int main() { int v = { 12, 34...
7
by: Jeff Schwab | last post by:
The latest GCC (4.2.3) gives a warning if a tr1::array is initialized with the traditional syntax: #include <iostream> #include <tr1/array> int main() { std::tr1::array<int, 35a = { 0 };...
3
by: Carter | last post by:
I am currently writing some code where I have a list of objects with a maximum occupancy of 4. I have been employing std::vector for this but I was wondering how much overhead is involved. Is it...
5
by: zr | last post by:
Hi, Is there a way to initialize a std::tr1::array with a pre-allocated built-in array in a copy-less assignment, such that both will point to the same memory? Vice-versa is easy to do, simply...
0
by: zr | last post by:
On Nov 10, 6:35 pm, Maxim Yegorushkin <maxim.yegorush...@gmail.com> wrote: I had to write a small test to realize the problem, though i don't understand what is really happening. Max, or anyone...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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
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...
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...

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.