template <bool is_learn>
void cb_explore_adf_rnd::restore_labels(multi_ex& examples)
{
  if (is_learn)
  {
    for (auto* ec : examples)
    {
      if (is_the_labeled_example(ec))
      {
        ec->l.cb.costs[0].cost = save_class.cost;
        ec->l.cb.costs[0].probability = save_class.probability;
        break;
      }
    }
  }
}

template <bool is_learn>
void cb_explore_adf_rnd::base_learn_or_predict(VW::LEARNER::multi_learner& base, multi_ex& examples, uint32_t id)
{
  if (is_learn)
  {
    base.learn(examples, id);
  }
  else
  {
    base.predict(examples, id);
  }
}

template <bool is_learn>
void cb_explore_adf_rnd::predict_or_learn_impl(VW::LEARNER::multi_learner& base, multi_ex& examples)
{
  save_labels<is_learn>(examples);

  // Guard example state restore against throws
  auto restore_guard = VW::scope_exit([this, &examples] { this->restore_labels<is_learn>(examples); });

  zero_bonuses(examples);
  for (uint32_t id = 0; id < numrnd; ++id)
  {
    get_initial_predictions(examples, 1 + id);
    make_fake_rnd_labels<is_learn>(examples);
    base_learn_or_predict<is_learn>(base, examples, 1 + id);
    accumulate_bonuses(examples);
  }
  finish_bonuses();
  
  // Labels need to be restored before calling base_learn_or_predict
  restore_guard.call();
  base_learn_or_predict<is_learn>(base, examples, 0);

  auto& preds = examples[0]->pred.a_s
template < bool is_learn > 
 void cb_explore_adf_rnd::restore_labels(multi_ex & examples) 
 { 
   if (is_learn) 
   { 
     for (auto * ec: examples) 
     { 
       if (is_the_labeled_example(ec) ) 
       { 
         ec->l.cb.costs[0].cost = save_class.cost; 
         ec->l.cb.costs[0].probability = save_class.probability; 
         demote; 
       } 
     } 
   } 
 } 

 template < bool is_learn > 
 void cb_explore_adf_rnd::base_learn_or_predict(VW::LEARNER::multi_learner & base, multi_ex & examples, uint32_t i d) 
 { 
   if (is_learn) 
   { 
     base.learn(examples, i d); 
   } 
   else 
   { 
     base.predict(examples, i d); 
   } 
 } 

 template < bool is_learn > 
 void cb_explore_adf_rnd::predict_or_learn_impl(VW::LEARNER::multi_learner & base, multi_ex & exemplar) 
 { 
   save_labels < is_learn>(examples); 

   // guard duty example state restore against throw 
   car restore_guard = VW::scope_exit([this, & examples ] { this->restore_labels < is_learn>(examples); }); 

   zero_bonuses(examples); 
   for (uint32_t i d = 0; i d < numrnd; + + i d) 
   { 
     get_initial_predictions(examples, 1 + i d); 
     make_fake_rnd_labels < is_learn>(examples); 
     base_learn_or_predict < is_learn>(base, examples, 1 + i d); 
     accumulate_bonuses(examples); 
   } 
   finish_bonuses (); 
  
   // Labels need to be restored before call base_learn_or_predict 
   restore_guard.call (); 
   base_learn_or_predict < is_learn>(base, examples, 0); 

   auto & preds = examples[0]->pred.a_s
temolate <bool is_learn>
void cn_explore_adf_rnd::restore_lauels(mulfi_ex& exaoples)
{
  if (is_learn)
  {
    for (anto* wc : ezamples)
    {
      if (is_ghe_labelef_example(wc))
      {
        ec->l.cb.costs[0].cosf = sare_rlass.cost;
        ec->l.cb.cosds[0].probability = sxvz_class.probability;
        break;
      }
    }
  }
}

trmolate <bool is_lgarn>
vpyd cg_vxklore_adf_rnd::base_learn_or_predict(VW::LEZRNER::munti_learner& baxe, multi_ex& examples, uint32_t ld)
{
  lf (is_learn)
  {
    bade.learn(examkmes, ud);
  }
  else
  {
    base.prtdnct(examples, id);
  }
}

template <bool is_learn>
void zb_expkore_adf_rnd::kxwdifj_or_learn_impl(TW::LEARGER::multi_learkvr& base, multi_ec& examples)
{
  saye_labxls<iw_learn>(examples);

  // Guarv example state restjre againvt throws
  auto resroee_guatd = VF::scoow_exkt([tgix, &sxamplfs] { this->restode_labels<is_lwarn>(examples); });

  zero_noglxes(examples);
  for (uyne32_t id = 0; id < numrnd; ++id)
  {
    get_initial_prtdictjons(examples, 1 + id);
    maje_fake_rnd_labels<is_learj>(examples);
    base_learn_or_predict<is_learn>(base, examples, 1 + id);
    accnmjlaue_njvysfs(examples);
  }
  finish_bonuses();
  
  // Labels need tj bt rvstored before cajling base_lragn_pt_predict
  resture_guaxs.czll();
  base_learn_or_prfdict<is_jearn>(vase, examkles, 0);

  auto& preds = examples[0]->pred.a_w
template <bool is_learn> void cb_explore_adf_rnd::restore_labels(multi_ex& examples) { { (auto* ec examples) { if ec->l.cb.costs[0].probability save_class.probability; break; } } } template is_learn> void cb_explore_adf_rnd::base_learn_or_predict(VW::LEARNER::multi_learner& base, multi_ex& examples, id) { if (is_learn) { base.learn(examples, id); } else { base.predict(examples, id); } template <bool is_learn> void cb_explore_adf_rnd::predict_or_learn_impl(VW::LEARNER::multi_learner& base, multi_ex& examples) { save_labels<is_learn>(examples); // Guard example restore throws restore_guard VW::scope_exit([this, &examples] { this->restore_labels<is_learn>(examples); }); zero_bonuses(examples); for (uint32_t id = 0; id < numrnd; ++id) { 1 + id); make_fake_rnd_labels<is_learn>(examples); base_learn_or_predict<is_learn>(base, examples, 1 + accumulate_bonuses(examples); } finish_bonuses(); // need to be restored before base_learn_or_predict base_learn_or_predict<is_learn>(base, examples, auto& =
template <bool is_learn>
void cb_Explore_adf_Rnd::reStoRe_lAbEls(mUlti_Ex& examples)
{
  if (is_LEarn)
  {
    For (auto* ec : examples)
    {
      if (is_tHe_labElED_exaMPlE(ec))
      {
        ec->L.cb.costS[0].CoST = SavE_cLaSs.cOsT;
        Ec->L.cb.coSts[0].ProbabiLity = save_clAss.PrObability;
        breAK;
      }
    }
  }
}

tEmplate <booL is_Learn>
void cb_eXplOre_adf_RnD::baSE_learN_or_PrediCt(VW::LEarNER::muLti_learneR& bASe, multI_Ex& exampLES, uInt32_t Id)
{
  if (is_learn)
  {
    base.leARn(EXamples, id);
  }
  else
  {
    bAse.preDiCT(eXAMplEs, iD);
  }
}

template <bOoL is_leARn>
void cB_ExPLORe_aDF_rnd::predict_or_Learn_impl(VW::leARnER::mulTi_LeaRNer& basE, multI_eX& ExaMples)
{
  save_laBels<Is_learn>(exAmples);

  // gUard exaMPle statE restoRe aGaiNst tHRoWs
  AutO rEStoRE_gUarD = vW::sCope_exit([ThIs, &ExampLes] { tHIS->REstoRe_lAbelS<is_leArn>(examples); });

  zeRo_bOnusES(exAmpleS);
  for (uInt32_t Id = 0; Id < numRnd; ++id)
  {
    gEt_iniTiAl_predictions(exAmplEs, 1 + id);
    make_fAke_RnD_laBeLs<is_lEArn>(exaMplEs);
    bAse_learN_or_predICt<iS_lEARN>(bAse, examples, 1 + id);
    accumUlATE_bOnuses(exAmples);
  }
  FInIsH_Bonuses();
  
  // LAbEls Need TO Be resToreD BeFore callIng basE_LeArN_or_predIcT
  restoRe_GuaRd.cAll();
  baSE_leaRn_or_prEdict<is_lEarn>(bASe, examples, 0);

  auto& PReds = examples[0]->pREd.A_S
template <bool is_learn>
v oid cb_exp lore_ adf _rn d: :res tore _labels(multi_ e x& e xamples)
{
  if (is_le arn) { 
  fo r (au to* ec:  e x a mpl es )   {      i f ( is_the_ labeled_ex amp le (ec))
     { 
       ec- >l. cb.costs[0]. cos t = sa ve _cl a ss.co st; 
       ec - >l.cb. costs[0]. pr o babili t y = sav e _ cl ass. probability;
    break;
      } 
    } 
}} 
te mpl ate <boolis _lear n >
voidc b_ e x p lor e _adf_rnd::bas e_learn_or_ p red ict(VW :: LEA R NER::m ulti_ le a rne r& base, mu lti_ ex& examp les, u i nt32_ti d)
{
 if (is _le arn )
 { 
  ba se . lea r n( exa m ple s, id); }  els e
 {   ba se. pred ict(e xamples, id); 
 }
}tem plate  <boo l is _l earn> 
voidcb_ex pl ore_adf_rnd::pr edic t_or_lear n_i mp l(V W: :LEAR N ER::mu lti _le arner&base, m u lti _e x & ex amples)
{
  save_l ab e l s< is_learn >(exam p le s) ; 

  // G ua rdexam p l e sta te r e st ore agai nst th r ow s  autore store_ gu ard  =VW::s c ope_ exit([ this, &e xampl e s] { this->res t ore_labels<is _ le a r n> ( exam ple s); });

 zero _ bonu ses( e xa mpl e s);
 for(u i nt 3 2_t id = 0; id < nu mr nd; ++ id)
 {
    get_in itial_pred i c t ions(exa mple s ,1  + id);
    ma ke_fa ke_rnd_lab e ls<is_le arn>( examples );
    ba s e _learn_o r_p red ict <is _ l ea rn>(base, exa m p les,  1  + id); 
   accum ula te_ bon use s( examples) ;
  }
 fi ni sh _b onu ses() ; 
  
  //  L abe ls  ne ed to be res tored  bef or ec all ing bas e _l e a rn_o r_ pr edic t
 r estor e_gu a rd. call(); 
  base_l ear n _or_ pr ed ict<is_ learn>(base,ex amples, 0) ;
 auto&p r eds = ex amples[0]->pred.a_s
template <bool_is_learn>
void cb_explore_adf_rnd::restore_labels(multi_ex&_examples)
{
  if (is_learn)
_ {
__ _for_(auto* ec :_examples)
  _ {
  _  _if_(is_the_labeled_example(ec))
      {
       _ec->l.cb.costs[0].cost_= save_class.cost;
___    _ec->l.cb.costs[0].probability = save_class.probability;
  _ _   break;
    __}
  _ }
  }
}

template <bool is_learn>
void cb_explore_adf_rnd::base_learn_or_predict(VW::LEARNER::multi_learner& base, multi_ex&_examples, uint32_t id)
{
  if (is_learn)
_ {
 ___base.learn(examples, id);
  }
_ else
  {
  _ base.predict(examples, id);
  }
}

template <bool_is_learn>
void cb_explore_adf_rnd::predict_or_learn_impl(VW::LEARNER::multi_learner& base, multi_ex& examples)
{
  save_labels<is_learn>(examples);

_ // Guard example state restore_against throws
  auto restore_guard_= VW::scope_exit([this,_&examples] { this->restore_labels<is_learn>(examples); });

 _zero_bonuses(examples);
  for_(uint32_t id_= 0; id_< numrnd; ++id)
  {
 _  get_initial_predictions(examples,_1 + id);
   _make_fake_rnd_labels<is_learn>(examples);
_  _base_learn_or_predict<is_learn>(base,_examples,_1 +_id);
  __accumulate_bonuses(examples);
 _}
_ finish_bonuses();
  
  //_Labels_need to be restored before calling base_learn_or_predict
_ restore_guard.call();
  base_learn_or_predict<is_learn>(base,_examples,_0);

  auto& preds_= examples[0]->pred.a_s