Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8926993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:07:08+00:00 2026-06-15T08:07:08+00:00

I have a function that expects a templated iterator type. It currently dereferences the

  • 0

I have a function that expects a templated iterator type.

It currently dereferences the iterator to inspect the type being iterated.

template < typename Iterator >
void func( Iterator i )
{
  // Inspect the size of the objects being iterated
  const size_t type_size = sizeof( *i );

  ...
}

I recently discovered that several of the standard iterator types, such as std::insert_iterator define *i as simply a reference to i.

That is, sizeof(*i) is the size of the iterator itself; the same as sizeof(i) or sizeof(***i)

Is there a universal way (supporting C++ 03) to determine the size or type of objects being iterated by any standard iterator?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T08:07:11+00:00Added an answer on June 15, 2026 at 8:07 am

    I’m not sure why you would want the value_type of an OutputIterator, because there is no way to extract a value from an Output Iterator. However, the three insert iterator adaptors all define value_type to be void and provide a container_type type member, so you could fall back to the value_type of T::container_type if the value_type of T turns out to be void.

    (By “value_type of” I really mean std::iterator_traits<T::container_type>::value_type and std::iterator_traits<T>::value_type.)

    Or you could just not try to use Output Iterators as though they had values 🙂

    Edit: SFINAE isn’t necessary: (even without C++11 niceness)

    template<typename U, typename T> struct helper {typedef U type;};
    
    // ostream*_iterator handling courtesy Drew Dormann
    template <typename T, typename charT, typename traits>
    struct helper<void, std::ostream_iterator<T, charT, traits> > {typedef T type;};
    
    template <typename charT, typename traits>
    struct helper<void, std::ostreambuf_iterator<charT, traits> > {typedef charT type;};
    
    // std::raw_storage_iterator still needs an override
    // as well as any non-standard output iterators which don't define a container_type.
    
    template<typename T> struct helper<void, T>
    {typedef typename std::iterator_traits<typename T::container_type>::value_type type;};
    
    typedef<typename It> struct my_value_type
      : public helper<typename std::iterator_traits<It>::value_type, It> {}; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a function that expects a block: void foo(Foo (^block)(Bar)); And say
I have a control that has a Filter property that expects a function that
Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
I have a C library function that expects a function pointer for callback, and
I have the following $.post() function that expects JSON as its return value. $.post($(this).attr(action),
Inside my Controller i have function that runs after user clicks on item, which
So I have function that formats a date to coerce to given enum DateType{CURRENT,
In my Java code I have function that gets file from the client in
I have function Start() that is fired on ready. When I click on .ExampleClick
I have a function that returns two values in a list. Both values need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.