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

  • SEARCH
  • Home
  • 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 6627863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:03:49+00:00 2026-05-25T22:03:49+00:00

I’m trying to make a watertight interface to a library that I’m designing. The

  • 0

I’m trying to make a watertight interface to a library that I’m designing. The user is to enter two dimensional data and so I thought an iterator interface similar to std::transform would be transparant.
However, I am unsure how to exception handle any abuse of the iterators.

My interface is like so (I can change the interface if there is a better one):

template<typename InputItrX, typename InputItrY>
set_data(InputItrX beginX, InputItrX endX, InputItrY beginY)
{
  //What exception handling should I do here?
  size_t array_size = endX-beginX;  //get the size of the xarray.
  my_xVector.resize(array_size);    //resize my internal container
  my_yVector.resize(array_size);    //  ..and for the ydata.
  std::copy(beginX, endX, my_xVector.begin());               //copy X
  std::copy(beginY, beginY+array_size, my_yVector.begin());  //copy Y
}

For example, my program becomes undefined if the user get muddled up with the interface and writes

set_data(xdata.begin(), ydata.begin(), xdata.end());

or maybe their xdata has 20 elements but their ydata has none.

Is it possible to check for such mistakes in my library interface?

  • 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-05-25T22:03:50+00:00Added an answer on May 25, 2026 at 10:03 pm

    I wouldn’t add any checks to the method, but document that the exception specification depends on the used iterators. So the user can use checked iterators if he doesn’t care about performance losses or unchecked iterators and get best performance. I think most implementations of STL iterators has asserts that check for iterator incompatibilities. Theses errors don’t need check in release mode, because they are programmer mistakes.

    size_t array_size = endX-beginX;  //get the size of the xarray.
    my_xVector.resize(array_size);    //resize my internal container
    my_yVector.resize(array_size);    //  ..and for the ydata.
    

    This makes your method incompatible with iterators that don’t have the -operator! It can be used only with random access iterator. You should extract this to a resize_vectors template which can be implemented for random access iterators, but doesn’t make any resize for other iterators. In the std::copy you have to use an inserter iterator that resizes the vector, while inserting if the vectors don’t have enough capacity.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I need to clean up various Word 'smart' characters in user input, including but
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.