YAPC::EU 2018 Glasgow Update!

This commit is contained in:
Ingy döt Net 2018-08-17 15:15:24 +01:00
parent 22f33d4004
commit 4e2d22a71d
1170 changed files with 15042 additions and 3047 deletions

View file

@ -1,11 +1,44 @@
#include <string>
#include <iostream>
// Variable argument template
int main( ) {
std::string original( "Mary had a X lamb." ) , toBeReplaced( "X" ) ,
replacement ( "little" ) ;
std::string newString = original.replace( original.find( "X" ) ,
toBeReplaced.length( ) , replacement ) ;
std::cout << "String after replacement: " << newString << " \n" ;
return 0 ;
#include <string>
#include <vector>
using std::string;
using std::vector;
template<typename S, typename... Args>
string interpolate( const S& orig , const Args&... args)
{
string out(orig);
// populate vector from argument list
auto va = {args...};
vector<string> v{va};
size_t i = 1;
for( string s: v)
{
string is = std::to_string(i);
string t = "{" + is + "}"; // "{1}", "{2}", ...
try
{
auto pos = out.find(t);
if ( pos != out.npos) // found token
{
out.erase(pos, t.length()); //erase token
out.insert( pos, s); // insert arg
}
i++; // next
}
catch( std::exception& e)
{
std::cerr << e.what() << std::endl;
}
} // for
return out;
}