Examples: improve C++ style

* examples/variant.yy: Prefer vector to list.
Remove useless inline.
This commit is contained in:
Akim Demaille
2018-05-12 14:04:04 +02:00
parent 2b5a27ba3d
commit 370a302f34

View File

@@ -25,9 +25,9 @@
%code requires // *.hh %code requires // *.hh
{ {
#include <list>
#include <string> #include <string>
typedef std::list<std::string> strings_type; #include <vector>
typedef std::vector<std::string> strings_type;
} }
%code // *.cc %code // *.cc
@@ -43,14 +43,14 @@ typedef std::list<std::string> strings_type;
static parser::symbol_type yylex (); static parser::symbol_type yylex ();
} }
// Printing a list of strings. // Printing a vector of strings.
// Koening look up will look into std, since that's an std::list. // Koening look up will look into std, since that's an std::vector.
namespace std namespace std
{ {
std::ostream& std::ostream&
operator<< (std::ostream& o, const strings_type& ss) operator<< (std::ostream& o, const strings_type& ss)
{ {
o << "(" << &ss << ") {"; o << '(' << &ss << ") {";
const char *sep = ""; const char *sep = "";
for (strings_type::const_iterator i = ss.begin(), end = ss.end(); for (strings_type::const_iterator i = ss.begin(), end = ss.end();
i != end; ++i) i != end; ++i)
@@ -58,13 +58,12 @@ typedef std::list<std::string> strings_type;
o << sep << *i; o << sep << *i;
sep = ", "; sep = ", ";
} }
return o << "}"; return o << '}';
} }
} }
// Conversion to string. // Conversion to string.
template <typename T> template <typename T>
inline
std::string std::string
string_cast (const T& t) string_cast (const T& t)
{ {
@@ -80,7 +79,7 @@ typedef std::list<std::string> strings_type;
%token END_OF_FILE 0; %token END_OF_FILE 0;
%type <::std::string> item; %type <::std::string> item;
%type <::std::list<std::string>> list; %type <::std::vector<std::string>> list;
%% %%