home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 33,136 of 33,346   
   frank67x@googlemail.com to All   
   Re: What are some simple, practical exam   
   22 Jul 13 10:37:31   
   
   it goes like this:   
      
   =============================================   
   #include    
   #include    
      
   using namespace boost;   
      
   std::string   
   GenerateString(   
   	char const * const str)   
   {   
   	std::cout << "GenerateString(): invoked" << std::endl;   
   	return std::string(str);   
   }   
      
   std::string   
   GetDefaultStr(   
   	std::string const & def)   
   {   
   	std::cout << "GetDefaultStr(): invoked" << std::endl;   
      
   	return def;   
   }   
      
   template    
   void   
   SetStr(   
   	std::string & str,   
   	Expr const & expr)   
   {   
   	std::cout << "MakeStr(): invoked" << std::endl;   
      
   	if (not str.empty())   
   	{   
   		return;   
   	}   
      
   	str = proto::eval(expr, proto::default_context());   
   }   
      
   int main(   
   	int,   
   	char**)   
   {   
   	// turn str into "x" then  GetDefaultStr()   
   	// & GenerateString() WON'T be invoked   
   	std::string str = "";   
      
   	SetStr(	str,   
   		proto::make_expr(   
   				GetDefaultStr,   
   				proto::make_expr(   
   						GenerateString,   
   						"hello"   
   				)   
   		)   
   	);   
      
   	std::cout << str << std::endl;   
      
   	return 0;   
   }   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca