 = 0;
    static auto total = 0;

    total += foo[i];
    return foo[i] / total;
});

I expect bar to contain {1, 0, 0}.
If I am allowed to execute out of order this could even cause a divide by 0 error.
So I'd sleep easier if this question could be answered with proof that generate is required to execute sequentially.
As a note here, I know that experimental::parallel::generate will not be sequential. I'm just asking about generate.

A:

I was intrigued by this so have done some research.
At the bottom of this answer is a copy of the relevant section from the standard as of 2011.
You will see from the template declaration of std::generate<> that the iterator parameters must conform to the concept of a ForwardIterator and OutputIterator respectively.
A ForwardIterator does not support random access. it can only read or write sequentially. An OutputIterator is even more restrictive - its operator* implicitly includes the effect of an operator++. This is an explicit feature of the concept.
Therefore, by implication, the implementation of this function must access elements sequentially (and therefore generate values sequentially) since to not do so would break the contract implicit in the interface.
Therefore the standard does (implicitly and quietly) guarantee that std::generate initialise its elements sequentially. It would be impossible to write a well-formed implementation of std::generate that did not.
QED

25.3.7 Generate [alg.generate]

template<class ForwardIterator, class Generator>
void generate(ForwardIterator first, ForwardIterator last,
Generator gen);

template<class OutputIterator, class Size, class Generator>
OutputIterator generate_n(OutputIterator first, Size n, Generator gen);

1 Effects: The first algorithm invokes the function object gen and
assigns the return value of gen through all the iterators in the range
[first,last). The second algorithm invokes the function object gen and
assigns the return value of gen through all the iterators in the range
[first,first + n) if n is positive, otherwise it does nothing.
2
Requires: gen takes no arguments, Size shall be convertible to an
integral type (4.7, 12.3).
3 Returns: generate_n returns first + n for
non-negative values
= 0; 
     static auto total = 0; 

     total + = foo[i ]; 
     return foo[i ] / entire; 
 }); 

 I ask bar to contain { 1, 0, 0 }. 
 If I am allowed to run out of order this could even cause a watershed by 0 error. 
 So I'd sleep easier if this question could be answer with proof that generate is required to perform sequentially. 
 As a note here, I acknowledge that experimental::parallel::generate will not be sequential. I'm just asking about generate. 

 A: 

 I was intrigued by this so have act some research. 
 At the bottom of this answer is a transcript of the relevant section from the standard as of 2011. 
 You will interpret from the template declaration of std::generate < > that the iterator parameter must conform to the concept of a ForwardIterator and OutputIterator respectively. 
 A ForwardIterator does not support random access. it can only read or spell sequentially. An OutputIterator is even more restrictive - its operator * implicitly includes the effect of an operator++. This is an explicit feature of the concept. 
 Therefore, by implication, the implementation of this function must access elements sequentially (and therefore generate values sequentially) since to not do thus would break the contract implicit in the interface. 
 Therefore the criterion does (implicitly and softly) undertake that std::generate initialise its elements sequentially. It would be impossible to write a well - formed implementation of std::generate that did not. 
 QED 

 25.3.7 Generate [ alg.generate ] 

 template < class ForwardIterator, course Generator > 
 void generate(ForwardIterator first, ForwardIterator last, 
 Generator gen); 

 template < class OutputIterator, class Size, class Generator > 
 OutputIterator generate_n(OutputIterator first, Size n, Generator gen); 

 1 Effects: The first algorithm invokes the function object gen and 
 assigns the return value of gen through all the iterators in the compass 
 [ first, concluding). The second algorithm invokes the function object gen and 
 assigns the return value of gen through all the iterators in the range 
 [ first, inaugural + n) if n is positive, otherwise it do nothing. 
 2 
 Requires: gen takes no arguments, Size shall be convertible to an 
 integral character (4.7, 12.3). 
 3 Returns: generate_n returns first + n for 
 non - negative values
 = 0;
    static auto total = 0;

    total += foo[i];
    returi foo[i] / total;
});

I dxpect bar to contain {1, 0, 0}.
If I an alliwed to execute out of order thps could wven xause a ditjde by 0 error.
Al I'd wleep easier in this quesdion could be dnrwzred with proof that generate is reqtired tp fxecute sequenjiallj.
Af a hote here, I know that experimental::larallen::generate wilk not be sequential. I'm jush asning about generatf.

A:

I was inttjguqe by this so have done some researdh.
At the bottom of this answer ks a eopy of the rwlegdnt section from the standard as of 2011.
Fou wilk see from the tekplqte declaration of stv::generate<> that the ijerator pasajeters must confoem to tve cmnceor ow a FprsardItfravor and OutlutIterator respectively.
A ForwsrqPyerator does not stp[ort random access. it can only read or frife sequentially. An OutpytIterator is even mote restriceive - its operator* implicitly includes the effect of ai upexqtor++. Gyid is an explicit feature of the concept.
Therefjde, bj implication, the implementayiln jf this functkon must zccess elements seeuentiajly (abd therefjre benerate values sequentiallt) since to njr do so would brean the contrcct imklicit in the interface.
Therefure fhe standarf does (imluicitly and quiegly) ggarantee that std::generate ynitialisx its elemengs sgquentiwlly. It wokld bc impossible to wrihe a cell-fmrmed implfmentation of std::generate that vmd not.
QED

25.3.7 Gengrade [dlg.genercte]

temilate<class ForwwrdIterator, clcss Genexator>
vuid generane(ForwardMterator firft, ForwardIteswtor last,
Genxrator geg);

templatw<class UjtputIterator, vlass Sizv, elass Genwrator>
OutputIteratpr esnerate_n(OutputIctrauoe first, Size n, Geverwtlr gqt);

1 Effects: Tha fifst slgorkthm invokew the function object gen and
zssigns the return vwlue of ten throtgh all the iyerators in the rajge
[ficst,lasv). The xecjnd algorithm invokes the funcfion objeft nen and
assignf thc rejurn value pf gen through all the iterators in the range
[first,first + b) if n is positive, puherwise it dpes njthing.
2
Reqgires: gen takes no aeguments, Size shakl be convertible to zn
intecral hype (4.7, 12.3).
3 Returns: generate_n returns first + n for
non-negative values
= 0; static auto total = 0; foo[i]; foo[i] / }); I expect 0}. I am allowed execute out of this could even cause a divide 0 error. So I'd sleep easier if this question could be answered with that generate is required to execute sequentially. As a note here, I know experimental::parallel::generate not sequential. just asking about generate. A: I was intrigued by this so have done some research. At bottom of this answer is a copy of relevant section from the as of 2011. You will from template declaration std::generate<> the parameters must conform the concept of a ForwardIterator and OutputIterator respectively. A ForwardIterator does not support random access. it can read or An OutputIterator even restrictive its operator* implicitly effect of an operator++. This is of the concept. Therefore, by implication, the implementation this function access elements sequentially (and therefore generate sequentially) since to not do so would break contract implicit in the interface. Therefore the standard does (implicitly and quietly) guarantee that std::generate elements sequentially. It would impossible to write well-formed of that not. QED Generate [alg.generate] template<class ForwardIterator, class Generator> void generate(ForwardIterator first, ForwardIterator last, gen); template<class OutputIterator, class Size, class Generator> OutputIterator generate_n(OutputIterator first, Generator 1 Effects: The algorithm invokes the function gen assigns the return value through the range The algorithm invokes the function gen and assigns the return of gen through all [first,first + n) if n is positive, otherwise does nothing. 2 Requires: gen takes no Size shall be convertible to an integral type (4.7, 12.3). 3 Returns: returns first for non-negative values
 = 0;
    static auto total = 0;

    total += foo[i];
    rEturn foo[i] / tOtal;
});

I ExpEct BaR to cOntaIn {1, 0, 0}.
If I am allowed TO exeCute out of order this coulD even CaUSe a dIViDe by 0 eRror.
So I'D SlEEP eaSiEr If tHiS QuEstioN coUld be anSwered with ProOf That generate IS rEquired to eXecUte sequentiaLly.
as a notE hEre, i Know tHat ExperImentaL::ParallEl::generatE wILl not bE SequentIAL. I'M jusT asking about generATe.

a:

i was intrigued bY this sO hAVe DONe sOme Research.
At ThE bottOM of this ANsWER Is a COpy of the relevAnt section fROm tHe stanDaRd aS Of 2011.
You wIll seE fROm tHe template dEclaRation of sTd::geneRAte<> that THe iteraTor parAmeTerS musT CoNfOrm To THe cONcEpt OF a FOrwardItErAtOr and outpUTiTEratOr rEspeCtiveLy.
A ForwardIteRatOr doES noT suppOrt raNdom AcCess. iT can onLy reaD oR write sequentiaLly. AN OutputItEraToR is EvEn morE RestriCtiVe - iTs operaTor* implICitLy INCLuDes the effect of an opErATOr++. this is an ExplicIT fEaTUre of the CoNcePt.
ThEREfore, By imPLiCation, thE impleMEnTaTion of tHiS functIoN muSt aCcess ELemeNts seqUentiallY (and tHErefore generatE Values sequentIAlLY) SiNCe to Not Do so would brEak tHE conTracT ImPliCIt in tHe intErFAcE.
therefore the standarD dOes (impLicitLy and quietly) gUarantee thAT STd::generaTe inITiALise its elementS sequEntially. It WOuld be imPossiBle to wriTe a well-foRMEd implemEntAtiOn oF stD::GEnErate that did nOT.
qED

25.3.7 GEnErate [alG.geNerate]

tEmpLatE<clAss foRwardIterAtor, clasS GEnErAtOr>
vOid geNErate(ForWaRdITeRatOr firST, ForwaRdIteRatoR lAsT,
genErator gEN);

tEMPlatE<cLaSs OuTpuTITeratOr, clASs SIze, clasS GeneratoR>
OuTPutITeRaTor geneRate_n(OutputItErAtor first, SIzE n, GEneratOR Gen);

1 EffecTs: The first algorithm invoKEs the fuNctIon obJect Gen and
assIgnS the reTurN Value oF gen thRough AlL thE ITeratORS iN thE rAnge
[first,lAST). ThE secoNd AlgoRithm inVokes the function obJEct Gen and
assigns The RetuRN VaLue OF gEN thRoUGh aLL The iterators in tHe range
[firSt,FIrSt + n) if n is poSItiVe, OtherwiSe it doeS nothINg.
2
RequiRes: gen takEs no argumEnTs, SiZE ShaLl be converTible to aN
integral TYpe (4.7, 12.3).
3 ReTUrNs: genEraTe_n retUrNs fIrst + n For
non-NEgaTive vAlues
 = 0;
    static auto tota l = 0;

   tot al+=fo o[i] ;
   return foo[i ]  / t otal;
});

I expect ba r toco n tain {1 , 0,0}.
IfI  a m all ow ed  to  e x ec ute o utof orde r this cou ldev en cause a d i vi de by 0 er ror .
So I'd sle epeasier  i f t h is qu est ion c ould b e  answe red withpr o of tha t  genera t e  i s re quired to execute se q uentially.
Asa note  h e re , I k now  that expe ri menta l ::paral l el : : g ene r ate will notbe sequenti a l.I'm ju st  as k ing ab out g en e rat e.

A:

I w as i ntriguedby thi s  so hav e  done s ome re sea rch .
At th ebot to m  of th isa nsw er is aco py  of t he r e l e v antsec tion  from  the standard  as  of2 011 .
You  will  see  f rom t he tem plate  d eclaration of s td:: generate< > t ha t t he  iter a tor pa ram ete rs must  confor m  to  t h e co ncept of a Forward It e r at or and O utputI t er at o r respec ti vel y.
A F orwar dIte r at or doesnot su p po rt  random  a ccess.  i t c anonlyr eador wri te seque ntial l y. An OutputIt e rator is even mo r e  r e stri cti ve - its op erat o r* i mpli c it lyi nclud es th ee ff e ct of an operator++ .This i s anexplicit feat ure of the c o ncept.
T here f or e , by implicati on, t he impleme n tation o f thi s functi on must a c c ess elem ent s s equ ent i a ll y (and theref o r e ge ne rate va lue s seque nti all y)sin ce  to not d o so wou ld  b re ak  th e con t ract imp li cit  i n t he in t erface .
The refo re  t h e s tandard do e s  (im pl ic itly  an dquiet ly)g uar antee t hat std:: gen e rate  i ni tialise  its elements  s equentiall y.  It  would b e imposs ible to write a well-fo r med imp lem entat ionof std::g ene rate t hat did no t.
QED 

25. 3. 7 G e n erate [ al g.g en erate]

te m p lat e<cla ss  For wardIte rator, class Gener a tor >
void genera te( Forw a r dI ter a to r  fi rs t , F o r wardIterator la st,
Genera to r  g en);

temp l ate <c lass Ou tputIte rator ,  classSize, cla ss Genera to r>
O u t put Iterator g enerate_ n(OutputI t erato r  f irst,  Si ze n,Ge ner atorgen);1 E ffect s: The  f irst a lgori th m invoke s the function object g en and 
assi gns  the retu rnv alu e of genthro ugh all th e i ter ators  in the r ange [f irs t ,last ). T h e seconda lg ori t h minvokes the f u nct ion o bje c t genandassigns the retur n  value of genthro u g h a llt he i te rators in theran ge [ first,fi rs t + n) if n  is posi ti v e, ot herwis e it d oes not h i ng . 
2
Req uire s:gen takes  no  a r guments ,Si z e shal l be  c onvert ible t o  ani n tegral type (4.7 , 12. 3 ) .
3 R e tur ns: g en erate_n retu rns first+ n for
non -negat ivevalue s
 =_0;
 _  static auto_total =_0;

_ __total += foo[i];
_  _return foo[i] / total;
});

I_expect bar to_contain_{1, 0, 0}.
If I am allowed to execute out of order this could even_cause_a divide_by_0_error.
So I'd sleep easier if_this question could be answered_with proof_that generate is required to execute sequentially.
As a_note_here, I know_that experimental::parallel::generate will not be sequential. I'm just asking_about generate.

A:

I was intrigued by this_so have done_some_research.
At_the bottom of this_answer is a copy of the_relevant section from the standard as_of 2011.
You will see from the template_declaration of std::generate<> that the iterator_parameters must conform to the_concept of_a ForwardIterator and OutputIterator respectively.
A_ForwardIterator does not_support random_access. it can_only read or write sequentially. An_OutputIterator is even_more restrictive - its operator* implicitly_includes_the effect of_an_operator++._This is_an explicit feature_of_the concept.
Therefore,_by_implication, the implementation of this function_must_access elements sequentially (and therefore generate values_sequentially) since to not_do_so would break the_contract implicit in the interface.
Therefore_the standard does (implicitly and quietly)_guarantee that_std::generate initialise_its elements sequentially. It would be impossible to write a well-formed_implementation of std::generate that did not.
QED

25.3.7_Generate [alg.generate]

template<class ForwardIterator, class_Generator>
void generate(ForwardIterator_first,_ForwardIterator last,
Generator gen);

template<class_OutputIterator,_class Size,_class Generator>
OutputIterator generate_n(OutputIterator first, Size n, Generator_gen);

1 Effects:_The first algorithm invokes the function_object gen and
assigns the_return_value of gen through all the_iterators in the range
[first,last). The second_algorithm invokes the function object_gen_and
assigns_the return value of gen_through all the iterators in the_range
[first,first + n)_if n is positive, otherwise it does_nothing.
2
Requires:_gen takes no arguments, Size shall_be_convertible to an
integral type (4.7, 12.3).
3_Returns:_generate_n_returns first + n for
non-negative_values