mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-21 10:13:03 +00:00
Examples: improve C++ style
* examples/variant.yy: Prefer vector to list. Remove useless inline.
This commit is contained in:
@@ -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;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user