Skip to content

Commit 63a083b

Browse files
committed
Remove uses of std::endl, which imply a flush
1 parent 8a30581 commit 63a083b

15 files changed

Lines changed: 75 additions & 79 deletions

include/chaiscript/dispatchkit/bootstrap.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ namespace chaiscript
207207

208208
static void println(const std::string &s)
209209
{
210-
std::cout << s << std::endl;
210+
std::cout << s << '\n';
211211
}
212212

213213

include/chaiscript/dispatchkit/boxed_cast.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,13 @@ namespace chaiscript
8989
if (t_conversions && t_conversions->convertable_type<Type>())
9090
{
9191
try {
92-
// std::cout << "trying an up conversion " << typeid(Type).name() << std::endl;
92+
// std::cout << "trying an up conversion " << typeid(Type).name() << '\n';
9393
// We will not catch any bad_boxed_dynamic_cast that is thrown, let the user get it
9494
// either way, we are not responsible if it doesn't work
9595
return detail::Cast_Helper<Type>::cast(t_conversions->boxed_type_conversion<Type>(bv), t_conversions);
9696
} catch (...) {
9797
try {
98-
// std::cout << "trying a down conversion " << typeid(Type).name() << std::endl;
98+
// std::cout << "trying a down conversion " << typeid(Type).name() << '\n';
9999
// try going the other way - down the inheritance graph
100100
return detail::Cast_Helper<Type>::cast(t_conversions->boxed_type_down_conversion<Type>(bv), t_conversions);
101101
} catch (const chaiscript::detail::exception::bad_any_cast &) {

include/chaiscript/dispatchkit/dispatchkit.hpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ namespace chaiscript
796796
/// Dump object info to stdout
797797
void dump_object(const Boxed_Value &o) const
798798
{
799-
std::cout << (o.is_const()?"const ":"") << type_name(o) << std::endl;
799+
std::cout << (o.is_const()?"const ":"") << type_name(o) << '\n';
800800
}
801801

802802
/// Dump type info to stdout
@@ -830,7 +830,7 @@ namespace chaiscript
830830
}
831831
}
832832

833-
std::cout << ") " << std::endl;
833+
std::cout << ") \n";
834834
}
835835

836836
/// Returns true if a call can be made that consists of the first parameter
@@ -850,28 +850,28 @@ namespace chaiscript
850850
/// Dump all system info to stdout
851851
void dump_system() const
852852
{
853-
std::cout << "Registered Types: " << std::endl;
853+
std::cout << "Registered Types: \n";
854854
std::vector<std::pair<std::string, Type_Info> > types = get_types();
855855
for (std::vector<std::pair<std::string, Type_Info> >::const_iterator itr = types.begin();
856856
itr != types.end();
857857
++itr)
858858
{
859859
std::cout << itr->first << ": ";
860860
std::cout << itr->second.bare_name();
861-
std::cout << std::endl;
861+
std::cout << '\n';
862862
}
863863

864-
std::cout << std::endl;
864+
std::cout << '\n';
865865
std::vector<std::pair<std::string, Proxy_Function > > funcs = get_functions();
866866

867-
std::cout << "Functions: " << std::endl;
867+
std::cout << "Functions: \n";
868868
for (std::vector<std::pair<std::string, Proxy_Function > >::const_iterator itr = funcs.begin();
869869
itr != funcs.end();
870870
++itr)
871871
{
872872
dump_function(*itr);
873873
}
874-
std::cout << std::endl;
874+
std::cout << '\n';
875875
}
876876

877877
/// return true if the Boxed_Value matches the registered type by name

include/chaiscript/dispatchkit/type_conversions.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -429,11 +429,7 @@ namespace chaiscript
429429
static_assert(std::is_convertible<From, To>::value, "Types are not automatically convertible");
430430
auto func = [](const Boxed_Value &t_bv) -> Boxed_Value {
431431
// not even attempting to call boxed_cast so that we don't get caught in some call recursion
432-
std::cout << " Type conversion to : " << typeid(To).name() << " from " << typeid(From).name() << std::endl;
433432
auto &&from = detail::Cast_Helper<From>::cast(t_bv, nullptr);
434-
std::cout << "Ptr" << static_cast<const void *>(from) << std::endl;
435-
std::cout << "Ptr" << from << std::endl;
436-
437433
To to(from);
438434
return chaiscript::Boxed_Value(to);
439435
};

include/chaiscript/language/chaiscript_common.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,19 @@ namespace chaiscript
118118

119119
ss << what();
120120
if (call_stack.size() > 0) {
121-
ss << "during evaluation at (" << fname(call_stack[0]) << " " << startpos(call_stack[0]) << ")" << std::endl;
122-
ss << std::endl << detail << std::endl;
121+
ss << "during evaluation at (" << fname(call_stack[0]) << " " << startpos(call_stack[0]) << ")\n";
122+
ss << '\n' << detail << '\n';
123123
ss << " " << fname(call_stack[0]) << " (" << startpos(call_stack[0]) << ") '" << pretty(call_stack[0]) << "'";
124124
for (size_t j = 1; j < call_stack.size(); ++j) {
125125
if (id(call_stack[j]) != chaiscript::AST_Node_Type::Block
126126
&& id(call_stack[j]) != chaiscript::AST_Node_Type::File)
127127
{
128-
ss << std::endl;
128+
ss << '\n';
129129
ss << " from " << fname(call_stack[j]) << " (" << startpos(call_stack[j]) << ") '" << pretty(call_stack[j]) << "'";
130130
}
131131
}
132132
}
133-
ss << std::endl;
133+
ss << '\n';
134134
return ss.str();
135135
}
136136

@@ -264,13 +264,13 @@ namespace chaiscript
264264
std::stringstream ss;
265265
if (t_functions.size() == 1)
266266
{
267-
ss << " Expected: " << format_types(t_functions[0], t_dot_notation, t_ss) << std::endl;
267+
ss << " Expected: " << format_types(t_functions[0], t_dot_notation, t_ss) << '\n';
268268
} else {
269-
ss << " " << t_functions.size() << " overloads available:" << std::endl;
269+
ss << " " << t_functions.size() << " overloads available:\n";
270270

271271
for (const auto & t_function : t_functions)
272272
{
273-
ss << " " << format_types((t_function), t_dot_notation, t_ss) << std::endl;
273+
ss << " " << format_types((t_function), t_dot_notation, t_ss) << '\n';
274274
}
275275

276276
}
@@ -430,7 +430,7 @@ namespace chaiscript
430430
std::ostringstream oss;
431431

432432
oss << t_prepend << "(" << ast_node_type_to_string(this->identifier) << ") "
433-
<< this->text << " : " << this->start.line << ", " << this->start.column << std::endl;
433+
<< this->text << " : " << this->start.line << ", " << this->start.column << '\n';
434434

435435
for (size_t j = 0; j < this->children.size(); ++j) {
436436
oss << this->children[j]->to_string(t_prepend + " ");

include/chaiscript/language/chaiscript_engine.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,11 +735,11 @@ namespace chaiscript
735735
{
736736
try {
737737
const auto name = elem + prefix + t_module_name + postfix;
738-
// std::cerr << "trying location: " << name << std::endl;
738+
// std::cerr << "trying location: " << name << '\n';
739739
load_module(version_stripped_name, name);
740740
return name;
741741
} catch (const chaiscript::exception::load_module_error &e) {
742-
// std::cerr << "error: " << e.what() << std::endl;
742+
// std::cerr << "error: " << e.what() << '\n';
743743
errors.push_back(e);
744744
// Try next set
745745
}

include/chaiscript/language/chaiscript_parser.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ namespace chaiscript
171171
/// Prints the parsed ast_nodes as a tree
172172
/*
173173
void debug_print(AST_NodePtr t, std::string prepend = "") {
174-
std::cout << prepend << "(" << ast_node_type_to_string(t->identifier) << ") " << t->text << " : " << t->start.line << ", " << t->start.column << std::endl;
174+
std::cout << prepend << "(" << ast_node_type_to_string(t->identifier) << ") " << t->text << " : " << t->start.line << ", " << t->start.column << '\n';
175175
for (unsigned int j = 0; j < t->children.size(); ++j) {
176176
debug_print(t->children[j], prepend + " ");
177177
}

samples/example.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@
1313

1414
void log(const std::string &msg)
1515
{
16-
std::cout << "[" << time(nullptr) << "] " << msg << std::endl;
16+
std::cout << "[" << time(nullptr) << "] " << msg << '\n';
1717
}
1818

1919
void log(const std::string &module, const std::string &msg)
2020
{
21-
std::cout << "[" << time(nullptr) << "] <" << module << "> " << msg << std::endl;
21+
std::cout << "[" << time(nullptr) << "] <" << module << "> " << msg << '\n';
2222
}
2323

2424
void bound_log(const std::string &msg)
@@ -28,12 +28,12 @@ void bound_log(const std::string &msg)
2828

2929
void hello_world(const chaiscript::Boxed_Value & /*o*/)
3030
{
31-
std::cout << "Hello World" << std::endl;
31+
std::cout << "Hello World\n";
3232
}
3333

3434
void hello_constructor(const chaiscript::Boxed_Value & /*o*/)
3535
{
36-
std::cout << "Hello Constructor" << std::endl;
36+
std::cout << "Hello Constructor\n";
3737
}
3838

3939

@@ -62,7 +62,7 @@ struct System
6262

6363
void take_shared_ptr(const std::shared_ptr<const std::string> &p)
6464
{
65-
std::cout << *p << std::endl;
65+
std::cout << *p << '\n';
6666
}
6767

6868
int main(int /*argc*/, char * /*argv*/[]) {
@@ -122,17 +122,17 @@ int main(int /*argc*/, char * /*argv*/[]) {
122122
//the templated version of eval:
123123
int i = chai.eval<int>("5+5");
124124

125-
std::cout << "5+5: " << i << std::endl;
125+
std::cout << "5+5: " << i << '\n';
126126

127127
//Add a new variable
128128
chai("var scripti = 15");
129129

130130
//We can even get a handle to the variables in the system
131131
int &scripti = chai.eval<int &>("scripti");
132132

133-
std::cout << "scripti: " << scripti << std::endl;
133+
std::cout << "scripti: " << scripti << '\n';
134134
scripti *= 2;
135-
std::cout << "scripti (updated): " << scripti << std::endl;
135+
std::cout << "scripti (updated): " << scripti << '\n';
136136
chai("print(\"Scripti from chai: \" + to_string(scripti))");
137137

138138
//To do: Add examples of handling Boxed_Values directly when needed

samples/memory_leak_test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class test
5454
chaiscript::Boxed_Value val = chai.eval_file(sFile);
5555
}
5656
catch (std::exception &e) {
57-
std::cout << e.what() << std::endl;
57+
std::cout << e.what() << '\n';
5858
}
5959
}
6060

src/main.cpp

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -136,24 +136,24 @@ std::vector<std::string> default_search_paths()
136136

137137
void help(int n) {
138138
if ( n >= 0 ) {
139-
std::cout << "ChaiScript evaluator. To evaluate an expression, type it and press <enter>." << std::endl;
140-
std::cout << "Additionally, you can inspect the runtime system using:" << std::endl;
141-
std::cout << " dump_system() - outputs all functions registered to the system" << std::endl;
142-
std::cout << " dump_object(x) - dumps information about the given symbol" << std::endl;
139+
std::cout << "ChaiScript evaluator. To evaluate an expression, type it and press <enter>.\n";
140+
std::cout << "Additionally, you can inspect the runtime system using:\n";
141+
std::cout << " dump_system() - outputs all functions registered to the system\n";
142+
std::cout << " dump_object(x) - dumps information about the given symbol\n";
143143
} else {
144-
std::cout << "usage : chai [option]+" << std::endl;
145-
std::cout << "option:" << std::endl;
146-
std::cout << " -h | --help" << std::endl;
147-
std::cout << " -i | --interactive" << std::endl;
148-
std::cout << " -c | --command cmd" << std::endl;
149-
std::cout << " -v | --version" << std::endl;
150-
std::cout << " - --stdin" << std::endl;
151-
std::cout << " filepath" << std::endl;
144+
std::cout << "usage : chai [option]+\n";
145+
std::cout << "option:" << '\n';
146+
std::cout << " -h | --help" << '\n';
147+
std::cout << " -i | --interactive" << '\n';
148+
std::cout << " -c | --command cmd" << '\n';
149+
std::cout << " -v | --version" << '\n';
150+
std::cout << " - --stdin" << '\n';
151+
std::cout << " filepath" << '\n';
152152
}
153153
}
154154

155155
void version(int){
156-
std::cout << "chai: compiled " << __TIME__ << " " << __DATE__ << std::endl;
156+
std::cout << "chai: compiled " << __TIME__ << " " << __DATE__ << '\n';
157157
}
158158

159159
bool throws_exception(const std::function<void ()> &f)
@@ -231,7 +231,7 @@ void interactive(chaiscript::ChaiScript& chai)
231231
//Then, we try to print the result of the evaluation to the user
232232
if (!val.get_type_info().bare_equal(chaiscript::user_type<void>())) {
233233
try {
234-
std::cout << chai.eval<std::function<std::string (const chaiscript::Boxed_Value &bv)> >("to_string")(val) << std::endl;
234+
std::cout << chai.eval<std::function<std::string (const chaiscript::Boxed_Value &bv)> >("to_string")(val) << '\n';
235235
}
236236
catch (...) {} //If we can't, do nothing
237237
}
@@ -241,11 +241,11 @@ void interactive(chaiscript::ChaiScript& chai)
241241
if (ee.call_stack.size() > 0) {
242242
std::cout << "during evaluation at (" << ee.call_stack[0]->start.line << ", " << ee.call_stack[0]->start.column << ")";
243243
}
244-
std::cout << std::endl;
244+
std::cout << '\n';
245245
}
246246
catch (const std::exception &e) {
247247
std::cout << e.what();
248-
std::cout << std::endl;
248+
std::cout << '\n';
249249
}
250250
}
251251
}
@@ -305,7 +305,7 @@ int main(int argc, char *argv[])
305305

306306
if ( arg == "-c" || arg == "--command" ) {
307307
if ( (i+1) >= argc ) {
308-
std::cout << "insufficient input following " << arg << std::endl;
308+
std::cout << "insufficient input following " << arg << '\n';
309309
return EXIT_FAILURE;
310310
} else {
311311
arg = argv[++i];
@@ -323,7 +323,7 @@ int main(int argc, char *argv[])
323323
} else if ( arg == "-i" || arg == "--interactive" ) {
324324
mode = eInteractive ;
325325
} else if ( arg.find('-') == 0 ) {
326-
std::cout << "unrecognised argument " << arg << std::endl;
326+
std::cout << "unrecognised argument " << arg << '\n';
327327
return EXIT_FAILURE;
328328
} else {
329329
mode = eFile;
@@ -335,16 +335,16 @@ int main(int argc, char *argv[])
335335
case eInteractive : interactive(chai); break;
336336
case eCommand : val = chai.eval(arg); break;
337337
case eFile : val = chai.eval_file(arg); break;
338-
default : std::cout << "Unrecognized execution mode" << std::endl; return EXIT_FAILURE;
338+
default : std::cout << "Unrecognized execution mode\n"; return EXIT_FAILURE;
339339
}
340340
}
341341
catch (const chaiscript::exception::eval_error &ee) {
342342
std::cout << ee.pretty_print();
343-
std::cout << std::endl;
343+
std::cout << '\n';
344344
return EXIT_FAILURE;
345345
}
346346
catch (std::exception &e) {
347-
std::cout << e.what() << std::endl;
347+
std::cout << e.what() << '\n';
348348
return EXIT_FAILURE;
349349
}
350350
}

0 commit comments

Comments
 (0)