THRIFT-1458 cpp: use the C++ standard (c++0x or later c++11) to improve code quality and cross platform capability
Signed-off-by: Nate Rosenblum <nater@maginatics.com>
diff --git a/compiler/cpp/src/generate/t_cpp_generator.cc b/compiler/cpp/src/generate/t_cpp_generator.cc
index 9eaf7ad..99c1ace 100644
--- a/compiler/cpp/src/generate/t_cpp_generator.cc
+++ b/compiler/cpp/src/generate/t_cpp_generator.cc
@@ -363,6 +363,8 @@
"#include <thrift/protocol/TProtocol.h>" << endl <<
"#include <thrift/transport/TTransport.h>" << endl <<
endl;
+ // Include C++xx compatibility header
+ f_types_ << "#include <thrift/cxxfunctional.h>" << endl;
// Include other Thrift includes
const vector<t_program*>& includes = program_->get_includes();
@@ -2436,12 +2438,12 @@
if (!(*f_iter)->is_oneway()) {
out <<
indent() << _this << "channel_->sendAndRecvMessage(" <<
- "std::tr1::bind(cob, this), " << _this << "otrans_.get(), " <<
+ "tcxx::bind(cob, this), " << _this << "otrans_.get(), " <<
_this << "itrans_.get());" << endl;
} else {
out <<
indent() << _this << "channel_->sendMessage(" <<
- "std::tr1::bind(cob, this), " << _this << "otrans_.get());" << endl;
+ "tcxx::bind(cob, this), " << _this << "otrans_.get());" << endl;
}
}
scope_down(out);
@@ -2742,8 +2744,8 @@
class_name_ = service_name_ + pstyle_ + "Processor";
if_name_ = service_name_ + "CobSvIf";
- finish_cob_ = "std::tr1::function<void(bool ok)> cob, ";
- finish_cob_decl_ = "std::tr1::function<void(bool ok)>, ";
+ finish_cob_ = "tcxx::function<void(bool ok)> cob, ";
+ finish_cob_decl_ = "tcxx::function<void(bool ok)>, ";
cob_arg_ = "cob, ";
ret_type_ = "void ";
} else {
@@ -2877,25 +2879,25 @@
: ", const " + type_name((*f_iter)->get_returntype()) + "& _return");
f_header_ <<
indent() << "void return_" << (*f_iter)->get_name() <<
- "(std::tr1::function<void(bool ok)> cob, int32_t seqid, " <<
+ "(tcxx::function<void(bool ok)> cob, int32_t seqid, " <<
"::apache::thrift::protocol::TProtocol* oprot, " <<
"void* ctx" << ret_arg << ");" << endl;
if (generator_->gen_templates_) {
f_header_ <<
indent() << "void return_" << (*f_iter)->get_name() <<
- "(std::tr1::function<void(bool ok)> cob, int32_t seqid, " <<
+ "(tcxx::function<void(bool ok)> cob, int32_t seqid, " <<
"Protocol_* oprot, void* ctx" << ret_arg << ");" << endl;
}
// XXX Don't declare throw if it doesn't exist
f_header_ <<
indent() << "void throw_" << (*f_iter)->get_name() <<
- "(std::tr1::function<void(bool ok)> cob, int32_t seqid, " <<
+ "(tcxx::function<void(bool ok)> cob, int32_t seqid, " <<
"::apache::thrift::protocol::TProtocol* oprot, void* ctx, " <<
"::apache::thrift::TDelayedException* _throw);" << endl;
if (generator_->gen_templates_) {
f_header_ <<
indent() << "void throw_" << (*f_iter)->get_name() <<
- "(std::tr1::function<void(bool ok)> cob, int32_t seqid, " <<
+ "(tcxx::function<void(bool ok)> cob, int32_t seqid, " <<
"Protocol_* oprot, void* ctx, " <<
"::apache::thrift::TDelayedException* _throw);" << endl;
}
@@ -3391,7 +3393,7 @@
out <<
"void " << tservice->get_name() << "AsyncProcessor" << class_suffix <<
"::process_" << tfunction->get_name() <<
- "(std::tr1::function<void(bool ok)> cob, int32_t seqid, " <<
+ "(tcxx::function<void(bool ok)> cob, int32_t seqid, " <<
prot_type << "* iprot, " << prot_type << "* oprot)" << endl;
scope_up(out);
@@ -3472,14 +3474,14 @@
// TODO(dreiss): Call the cob immediately?
out <<
indent() << "iface_->" << tfunction->get_name() << "(" <<
- "std::tr1::bind(cob, true)" << endl;
+ "tcxx::bind(cob, true)" << endl;
indent_up(); indent_up();
} else {
string ret_arg, ret_placeholder;
if (!tfunction->get_returntype()->is_void()) {
ret_arg = ", const " + type_name(tfunction->get_returntype()) +
"& _return";
- ret_placeholder = ", std::tr1::placeholders::_1";
+ ret_placeholder = ", tcxx::placeholders::_1";
}
// When gen_templates_ is true, the return_ and throw_ functions are
@@ -3487,7 +3489,7 @@
// can resolve the correct overloaded version.
out <<
indent() << "void (" << tservice->get_name() << "AsyncProcessor" <<
- class_suffix << "::*return_fn)(std::tr1::function<void(bool ok)> " <<
+ class_suffix << "::*return_fn)(tcxx::function<void(bool ok)> " <<
"cob, int32_t seqid, " << prot_type << "* oprot, void* ctx" <<
ret_arg << ") =" << endl;
out <<
@@ -3496,7 +3498,7 @@
if (!xceptions.empty()) {
out <<
indent() << "void (" << tservice->get_name() << "AsyncProcessor" <<
- class_suffix << "::*throw_fn)(std::tr1::function<void(bool ok)> " <<
+ class_suffix << "::*throw_fn)(tcxx::function<void(bool ok)> " <<
"cob, int32_t seqid, " << prot_type << "* oprot, void* ctx, " <<
"::apache::thrift::TDelayedException* _throw) =" << endl;
out <<
@@ -3508,13 +3510,13 @@
indent() << "iface_->" << tfunction->get_name() << "(" << endl;
indent_up(); indent_up();
out <<
- indent() << "std::tr1::bind(return_fn, this, cob, seqid, oprot, ctx" <<
+ indent() << "tcxx::bind(return_fn, this, cob, seqid, oprot, ctx" <<
ret_placeholder << ")";
if (!xceptions.empty()) {
out
<< ',' << endl <<
- indent() << "std::tr1::bind(throw_fn, this, cob, seqid, oprot, " <<
- "ctx, std::tr1::placeholders::_1)";
+ indent() << "tcxx::bind(throw_fn, this, cob, seqid, oprot, " <<
+ "ctx, tcxx::placeholders::_1)";
}
}
@@ -3544,7 +3546,7 @@
out <<
"void " << tservice->get_name() << "AsyncProcessor" << class_suffix <<
"::return_" << tfunction->get_name() <<
- "(std::tr1::function<void(bool ok)> cob, int32_t seqid, " <<
+ "(tcxx::function<void(bool ok)> cob, int32_t seqid, " <<
prot_type << "* oprot, void* ctx" << ret_arg_decl << ')' << endl;
scope_up(out);
@@ -3613,7 +3615,7 @@
out <<
"void " << tservice->get_name() << "AsyncProcessor" << class_suffix <<
"::throw_" << tfunction->get_name() <<
- "(std::tr1::function<void(bool ok)> cob, int32_t seqid, " <<
+ "(tcxx::function<void(bool ok)> cob, int32_t seqid, " <<
prot_type << "* oprot, void* ctx, " <<
"::apache::thrift::TDelayedException* _throw)" << endl;
scope_up(out);
@@ -4477,7 +4479,7 @@
? "()"
: ("(" + type_name(ttype) + " const& _return)"));
if (has_xceptions) {
- exn_cob = ", std::tr1::function<void(::apache::thrift::TDelayedException* _throw)> /* exn_cob */";
+ exn_cob = ", tcxx::function<void(::apache::thrift::TDelayedException* _throw)> /* exn_cob */";
}
} else {
throw "UNKNOWN STYLE";
@@ -4485,7 +4487,7 @@
return
"void " + prefix + tfunction->get_name() +
- "(std::tr1::function<void" + cob_type + "> cob" + exn_cob +
+ "(tcxx::function<void" + cob_type + "> cob" + exn_cob +
argument_list(arglist, name_params, true) + ")";
} else {
throw "UNKNOWN STYLE";
diff --git a/lib/cpp/src/thrift/cxxfunctional.h b/lib/cpp/src/thrift/cxxfunctional.h
index b3c6e3e..c24b91b 100644
--- a/lib/cpp/src/thrift/cxxfunctional.h
+++ b/lib/cpp/src/thrift/cxxfunctional.h
@@ -120,4 +120,7 @@
}}} // apache::thrift::stdcxx
#endif
+ // Alias for thrift c++ compatibility namespace
+ namespace tcxx = apache::thrift::stdcxx;
+
#endif // #ifndef _THRIFT_CXXFUNCTIONAL_H_