heut bin ich auf was gestossen, das das arbeiten mit templates und gcc wirklich vereinfacht.
Beispielcode;
Code: Alles auswählen
#include <iostream>
#include <string>
#include <list>
int main (int argc, char** argv)
{
std::list< std::string > l;
int t = 1;
l.push_back(&t);
}
Code: Alles auswählen
gcc filter.cpp
filter.cpp: In function ‘int main(int, char**)’:
filter.cpp:10: error: no matching function for call to ‘std::list<std::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::push_back(int*)’
/usr/include/c++/4.3/bits/stl_list.h:875: note: candidates are: void std::list<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = std::basic_string<char, std::char_traits<char>, std::allocator<char> >, _Alloc = std::allocator<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >]
Mit diesem kleinen Perlscript
Code: Alles auswählen
#!/usr/bin/perl -w
use strict;
use warnings;
while (<>)
{
s/std::basic_string<char, std::char_traits<char>, std::allocator<char> >\s*/std::string/g;
s/std::set<(.+?), std::less<\1>, std::allocator<\1> >/std::set<$1>/g;
s/std::list<(.+?), std::less<\1>, std::allocator<\1> >/std::list<$1>/g;
s/std::vector<(.+?), std::less<\1>, std::allocator<\1> >/std::vector<$1>/g;
print;
}
Code: Alles auswählen
gcc filter.cpp 2>&1 | ./g++filter.pl
filter.cpp: In function ‘int main(int, char**)’:
filter.cpp:10: error: no matching function for call to ‘std::list<std::string, std::allocator<std::string> >::push_back(int*)’
/usr/include/c++/4.3/bits/stl_list.h:875: note: candidates are: void std::list<_Tp, _Alloc>::push_back(const _Tp&) [with _Tp = std::string, _Alloc = std::allocator<std::string>]
Viel Spass damit
Gruß
schorsch
[1] http://www.enricozini.org/2007/tips/g++-parse/