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 165319
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:54:00+00:00 2026-05-11T11:54:00+00:00

I’ve implementation of UnaryOperation like this struct Converter { Converter( std::size_t value ): value_(

  • 0

I’ve implementation of UnaryOperation like this

struct Converter {     Converter( std::size_t value ):         value_( value ), i_( 0 )     {}     std::string operator() ( const std::string& word )     {         return ( value_ & ( 1 << i_++ ) ) ?             word:             std::string( word.size(), ' ' );     }     std::size_t value_;     std::size_t i_; }; 

And I use it like

std::vector v; // initialization of v   std::transform( v.begin(), v.end(),                 std::back_inserter( result ),                 Converter( data ) ); 

My question is can I rely on my assumption that algorithm will call my ‘Converter operator ()’ in the order that ‘Converter::i_’ will correspond to number of element in ‘v’.

Please quote the standard in case I can’t rely on the order or put the stl-like solution that avoid possible problem if any.

Thanks.

Edit:

I am aware of ‘no Side effect’ requirements in the standard for the transform algorithm. I can’t find what is exactly ‘side effect’ for functors in the same standard.

Maybe there is some good-looking-boost-like solution for this task?

  • 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. 2026-05-11T11:54:01+00:00Added an answer on May 11, 2026 at 11:54 am

    Qute from standard:

    25.2.3 Transform [lib.alg.transform]
    Requires:
    op and binary_op shall not have any side effects.

    Side Effect ( wikipedia definition )

    In your case we have next side effect:

    Converter c( data );   c( some_const_value ) != c( some_const_value ); 

    You don’t have any guarantees for your algorithms, but I belive that it will works on almost all stl implementations.

    Suggested solution
    It seems I know one way to do what you need:
    use boost::counting_iterator – for iterate over two containers;

    it will looks like:

    bool bit_enabled( size_t data, unsigned char number ) {     return ( data & 1 << number ) != 0; }  std::string select_word(                  const std::string& word,                 size_t data,                  size_t number ) {     return bit_enabled( data, number ) ? word : std::string( ' ', word.length() ); }  const size_t data = 7; const boost::array< std::string, 3 > vocabulary = { 'a', 'b', 'c' }; std::vector< std::string > result; std::transform(     vocabulary.begin(),     vocabulary.end(),     boost::counting_iterator< size_t >(0),     back_inserter( result ),     boost::bind( &select_word, _1, data, _2 ) ); 

    Also maybe if you will define bit iterator or will use some bit container you will can use boost::zip_iterator for iterate both containers.

    EDIT:
    Yestarday I found interest article which contain definition of Side Effect by standard.

    The Standard defines a side effect as follows: Accessing an object designated by a volatile lvalue, modifying an object, calling a library I/O function, or calling a function that does any of those operations are all side effects, which are changes in the state of the execution environment.

    EDIT:
    I hope it will be latest edit.
    I am always tought that ‘no have side effect’ mean:
    f(a) should be equal f(a) always. ( f independed from execution environment: memory/cpu/global variables/member variables as in your case etc).
    ‘Not produce side effect’ mean – don’t changing execution environment.

    But in c++ standard we have more low-level defintion for Side effect.

    Thing what you do in your example named as Stateful functor.
    Standard doesn’t say about ‘Statefull’ functors, but also doesn’t say about count of copies of your functor – you couldn’t use this trick because it is unspecified behavior.

    See Standard Library Issues list ( similar issue for predicat ):
    http://anubis.dkuug.dk/jtc1/sc22/wg21/docs/lwg-active.html#92

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

Sidebar

Ask A Question

Stats

  • Questions 82k
  • Answers 82k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I finally figured it out: sUser = "myusername" sDN =… May 11, 2026 at 4:39 pm
  • Editorial Team
    Editorial Team added an answer Part of the problem is that you are not pairing… May 11, 2026 at 4:39 pm
  • Editorial Team
    Editorial Team added an answer I found it. Make a file with a name such… May 11, 2026 at 4:39 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.