Below is my understanding about count algorithms.
Return type of count and count_if algorithms is
iterator_traits <InputIterator> ::difference_ty pe.
If the container contains more than 'difference_typ e' elements
satisfying the condition, then count and count_if algorithm cannot
return a value greater than 'difference_typ e'.
As an example, suppose maximum value of 'difference_typ e' is INT_MAX.
Then the corresponding maximum value of 'size_type' is UINT_MAX. Now
consider the declaration
vector<charv;
where 'v' contains UINT_MAX elements each of which is 'a'.
Now if I do
count(v.begin() , v.end(), 'a')
then the actual count would be UINT_MAX but it cannot be represented
in 'difference_typ e' which is the return type of count algorithm.
So' won't we get erroneous results from count algorithms ?
I understand that difference_type is same as ptrdiff_t for
pointers(belong ing to the same array) and size_type if same as size_t.
This means that the count algorithms can never return values from
ptrdiff_t + 1 upto size_t.
Is this understanding correct ?
If what I have mentioned is really a problem with count algorithms,
how should I count the elements in a container satisfying the
condition for large number of elements(ie greater than
difference_type ) ?
Kindly clarify.
Thanks
V.Subramanian
Jun 27 '08
12 2316
On 2008-04-27 17:59:37 -0400, "kwikius" <an**@servocomm .freeserve.co.u ksaid:
>
"Pete Becker" <pe**@versatile coding.comwrote in message
news:2008042711 481916807-pete@versatilec odingcom...
>On 2008-04-27 11:43:09 -0400, "kwikius" <an**@servocomm .freeserve.co.u k> said:
>>> The real problem is that containers have excessive requirements. arrays and lookups dont in practise need to be iterable at all, but you can still write generic algorithms. Remove the iterator paradigm and do for_each (container) in parallel for example. STL was a major innovator for generic programming but way way far from perfect.... Too many blooming iterators. Without iterators STL is something entirely different. Container-based algorithms are nowhere near as flexible as iterator-based ones, because the sequences that iterators refer to don't need to come from containers.
Most containers arent sequences... except in STL "every container must be a
list". This is a viewpoint imposed by the iterator paradigm.
This is a viewpoint imposed by the need to operate every element in a
container.
Custom conforming containers are very complicated to create as need to
provide full custom iterator shebang.
Rather than creating iterators it is just as possible to create views of
arbitrary entities as containers. You only need to create one container view
( as opposed to 2 iterators to create 2 ends of a container view ).
If you need to operate on every element in a container, you end up
treating the container as a sequence. Creating one container view
versus two iterators doesn't change that.
>
Containers can have simpler requirements... easier to fulfill requirements
and create custom containers
Since there is no description here of how this paradigm works, I can't
assess this assertion.
>
It is also possible to view one container type as another.
increases flexibility for the user and also enables the user to create
custom
containers more easily because each container type has fewer requirements.
But the most important point is it removes the necessity of exposing the
blooming iterators in every algorithm, which makes source code less
expressive :
fun(my_containe r, your_container , f) ; //overloaded or internally adapted
as against
fun(my_containe r.begin(), my_container.en d(), my_container.be gin(),
your_container. end(), f) ; //error?
At the cost of having to pretend that the keyboard, for example, is a
container rather than the source of a sequence of characters.
--
Pete
Roundhouse Consulting, Ltd. ( www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
( www.petebecker.com/tr1book)
"Pete Becker" <pe**@versatile coding.comwrote in message
news:2008042807 104016807-pete@versatilec odingcom...
On 2008-04-27 17:59:37 -0400, "kwikius" <an**@servocomm .freeserve.co.u k>
said:
>> "Pete Becker" <pe**@versatile coding.comwrote in message news:200804271 1481916807-pete@versatilec odingcom...
>>On 2008-04-27 11:43:09 -0400, "kwikius" <an**@servocomm .freeserve.co.u k>
<...>
>>Without iterators STL is something entirely different. Container-based algorithms are nowhere near as flexible as iterator-based ones, because the sequences that iterators refer to don't need to come from containers.
Most containers arent sequences... except in STL "every container must be a list". This is a viewpoint imposed by the iterator paradigm.
This is a viewpoint imposed by the need to operate every element in a
container.
Not all containers need to have every element operated on. lookup is an
example. You don't need to iterate a lookup for its main functionality . Now
when you need to iterate over a lookup you can create a listview, and not
just one but many, sorted by key , or key range sorted by value or value
range, arbitrary sort function, and even layer views. You can apply
functionality for the particular purpose when you need it and then discard
it.
> Custom conforming containers are very complicated to create as need to provide full custom iterator shebang.
Rather than creating iterators it is just as possible to create views of arbitrary entities as containers. You only need to create one container view ( as opposed to 2 iterators to create 2 ends of a container view ).
If you need to operate on every element in a container, you end up
treating the container as a sequence. Creating one container view versus
two iterators doesn't change that.
>> Containers can have simpler requirements... easier to fulfill requirements and create custom containers
Since there is no description here of how this paradigm works, I can't
assess this assertion.
Its about concepts dealing with one single functionality of a type in
expression rather than monolithic concepts covering large amounts of
functionality ( e.g HasPlus preferred to Arithmetic ) think of eg
ForEachableCont ainer CountIfAbleCont ainer etc, like the modern move from
"traits blob" to metafunctions.
<...>
>But the most important point is it removes the necessity of exposing the blooming iterators in every algorithm, which makes source code less expressive :
fun(my_contain er, your_container , f) ; //overloaded or internally adapted
as against
fun(my_contain er.begin(), my_container.en d(), my_container.be gin(), your_container .end(), f) ; //error?
At the cost of having to pretend that the keyboard, for example, is a
container rather than the source of a sequence of characters.
Oh don't get me started on istream.
Simple console input is a lazy list with customisable terminator... eg for
continuous multiline input, disc istream is array or tuple, database istream
a lookup etc...
regards
Andy Little
On 2008-04-28 13:31:34 -0400, "kwikius" <an**@servocomm .freeserve.co.u ksaid:
>
Not all containers need to have every element operated on.
In which case they don't have to have iterators.
lookup is an
example. You don't need to iterate a lookup for its main functionality .
Sigh. You have to be able to look at every element, i.e. "operate on"
every element.
>> Since there is no description here of how this paradigm works, I can't assess this assertion.
Its about concepts dealing with one single functionality of a type in
expression rather than monolithic concepts covering large amounts of
functionality ( e.g HasPlus preferred to Arithmetic ) think of eg
ForEachableCont ainer CountIfAbleCont ainer etc, like the modern move from
"traits blob" to metafunctions.
I'm sorry, I have no idea what that means.
>
<...>
>>But the most important point is it removes the necessity of exposing the blooming iterators in every algorithm, which makes source code less expressive :
fun(my_contai ner, your_container , f) ; //overloaded or internally adapted
as against
fun(my_contai ner.begin(), my_container.en d(), my_container.be gin(), your_containe r.end(), f) ; //error?
At the cost of having to pretend that the keyboard, for example, is a container rather than the source of a sequence of characters.
Oh don't get me started on istream.
Who said anything about istream? Regardless, you have to deal with the
issue of pretending that a keyboard is a container.
>
Simple console input is a lazy list with customisable terminator... eg for
continuous multiline input, disc istream is array or tuple, database istream
a lookup etc...
That's what I said: you have to pretend that the keyboard is a container.
--
Pete
Roundhouse Consulting, Ltd. ( www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
( www.petebecker.com/tr1book) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: JohanS |
last post by:
Hi
count(v.begin(), v.end(), 5) is easy for a vector of int's.
But how do i make it work with a class object? I have tried a few ways
but can't get it to work since i don't really understand how this
stuff works yet.
If i have class A with 2 int members that you get with A.x() and A.y()
and i want to use count or count_if if A.y() == value.
|
by: none |
last post by:
I have managed to get the below script *almost* working. However, it
still has a problem calculating the number of months. The date I am
trying to calculate from is Oct 15, 1994. With the correct "thatmonth"
(10) it displays 0. With 9 it displays 2, instead of 1 which would be
correct.
Any suggestions?
=== Cut ===
<script language=Javascript type=text/javascript class="smalltext">
|
by: tania |
last post by:
i have this table in my database:
CREATE TABLE FILM(
F_ID INT(5) NOT NULL AUTO_INCREMENT,
F_TITLE VARCHAR(40) NOT NULL,
DIRECTOR_FNAME VARCHAR(20) NOT NULL,
DIRECTOR_LNAME VARCHAR(20) NOT NULL,
TYPE VARCHAR(30) NOT NULL,
DURATION TIME ,
YEAR_RELEASE YEAR NOT NULL,
DESCRIPTION TEXT,
|
by: Gary Wessle |
last post by:
Hi
I have a vector<charwhich looks like this (a d d d a d s g e d d d d
d k)
I need to get the biggest count of consecutive 'd'. 5 in this example
I am toying with this method but not sure if it is optimal.
thanks
int k = 0;
|
by: MP |
last post by:
vb6,ado,mdb,win2k
i pass the sql string to the .Execute method on the open connection to
Table_Name(const) db table
fwiw
(the connection opened via class wrapper:)
msConnString = "Data Source=" & msDbFilename
moConn.Properties("Persist Security Info") = False
moConn.ConnectionString = msConnString
moConn.CursorLocation = adUseClient
moConn.Mode = adModeReadWrite' or using default...same result
| |
by: Pete |
last post by:
I need to create a single query (Not a SQL query) against a single
table that counts the number of records in the table, where the single
field "tmp" contains specific string values
If the field contains "AAA" the count is X.
if the field contains "CCC" the count is Y.
if the field contains "Stop" then count is Z.
I have tried several ways and can not seem to get any where. I get
the same count for all string values. Can some one...
|
by: zambia |
last post by:
First post so please excuse any Faux Pas's
I have an xml file as below
<?xml version="1.0"?>
<Car>
<Type>Ford Sierra</Type>
<Service>1
<Date>01/09/2006</Date>
<Tyres>OK</Tyres>
|
by: barcaroller |
last post by:
I am trying to adopt a model for calling functions and checking their return
values. I'm following Scott Meyer's recommendation of not over-using
exceptions because of their potential overhead.
Here's the approach I'm currently looking at. I throw exceptions only from
constructors. Destructors, of course, do not throw exceptions. All other
functions return a signed integer. The values are all stored in one large
header file (as...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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: 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: 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...
| |