Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > UNAVOIDABLE situation for the use of vector<T>::value_type

Reply
Thread Tools

UNAVOIDABLE situation for the use of vector<T>::value_type

 
 
subramanian100in@yahoo.com, India
Guest
Posts: n/a
 
      03-04-2008
For a type T, consider vector<T>::value_type. When is this member
'value_type' useful; in other words, when is the use of value_type
unavoidable?

Kindly clarify.

The reason for asking this question is the following:

For a particular type T, say std::string, Suppose I use,
vector<string>::value_type obj;
But, to initialize or assign a value to 'obj', we have to know the
actual type T. So we can simply declare
string obj;

In this example, the need for value_type is AVOIDABLE.

But there should be some genuine situation wherein the use of
value_type is UNAVOIDABLE. I am unable to come up with an example for
this unavoidable situation. Please clarify.

Thanks
V.Subramanian
 
Reply With Quote
 
 
 
 
Triple-DES
Guest
Posts: n/a
 
      03-04-2008
On 4 Mar, 06:56, "subramanian10...@yahoo.com, India"
<subramanian10...@yahoo.com> wrote:
> For a type T, consider vector<T>::value_type. When is this member
> 'value_type' useful; in other words, when is the use of value_type
> unavoidable?
>
> Kindly clarify.
>
> The reason for asking this question is the following:
>
> For a particular type T, say std::string, Suppose I use,
> vector<string>::value_type obj;
> But, to initialize or assign a value to 'obj', we have to know the
> actual type T. So we can simply declare
> string obj;
>
> In this example, the need for value_type is AVOIDABLE.
>
> But there should be some genuine situation wherein the use of
> value_type is UNAVOIDABLE. I am unable to come up with an example for
> this unavoidable situation. Please clarify.
>


template<typename Container>
void f(const Container& c)
{
if(c.empty() )
return;
// the only way to get the value_type at this point
Container::value_type t = *c.begin();
// ...
}

DP
 
Reply With Quote
 
 
 
 
Jerry Coffin
Guest
Posts: n/a
 
      03-04-2008
In article <9e01dd24-f5ff-4511-a4b5-fb64ee47f793
@d21g2000prf.googlegroups.com>, says...
> For a type T, consider vector<T>::value_type. When is this member
> 'value_type' useful; in other words, when is the use of value_type
> unavoidable?
>
> Kindly clarify.
>
> The reason for asking this question is the following:
>
> For a particular type T, say std::string, Suppose I use,
> vector<string>::value_type obj;
> But, to initialize or assign a value to 'obj', we have to know the
> actual type T. So we can simply declare
> string obj;
>
> In this example, the need for value_type is AVOIDABLE.
>
> But there should be some genuine situation wherein the use of
> value_type is UNAVOIDABLE. I am unable to come up with an example for
> this unavoidable situation. Please clarify.


Write a template to sum the elements in a container, and see if you
don't find a use for it.

--
Later,
Jerry.

The universe is a figment of its own imagination.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I avoid the use of arrays in this situation or do I have to usethem? mike3 C++ 47 12-05-2007 09:01 PM
Dependency Loop seems unavoidable Tim C++ 13 08-23-2007 06:54 PM
Sticky Situation - CSS11503 Load Balancer Qwik Cisco 1 08-18-2005 06:01 PM
Use of a Repeater control in tricky situation Alex ASP .Net Web Controls 1 10-03-2004 08:52 PM
Example where static variables are unavoidable... does it exist? TGOS Java 62 09-14-2003 08:04 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57