static void register_server_packet() { Derived x = Derived(); Derived::message_id = next_server_packet_id(); //set size Derived::size = x._size(); register_server_message_handler(Derived::message_id, Derived::size, &Derived::handler, x.get_packet_name()); //server/client handler }
int main() { try { throw Derived(); } catch(Base) { assert(0); } return 0; }
std::vector < Derived > lidarBoostEngine::lk_optical_flow( const MatrixBase<Derived>& I1, const MatrixBase<Derived> &I2, int win_sz) { //Instantiate optical flow matrices std::vector < Derived > uv(2); //Create masks Matrix2d robX, robY, robT; robX << -1, 1, -1, 1; robY << -1, -1, 1, 1; robT << -1, -1, -1, -1; Derived Ix, Iy, It, A, solutions, x_block, y_block, t_block; //Apply masks to images and average the result Ix = 0.5 * ( conv2d( I1, robX ) + conv2d( I2, robX ) ); Iy = 0.5 * ( conv2d( I1, robY ) + conv2d( I2, robY ) ); It = 0.5 * ( conv2d( I1, robT ) + conv2d( I2, robT ) ); uv[0] = Derived::Zero( I1.rows(), I1.cols() ); uv[1] = Derived::Zero( I1.rows(), I1.cols() ); int hw = win_sz/2; for( int i = hw+1; i < I1.rows()-hw; i++ ) { for ( int j = hw+1; j < I1.cols()-hw; j++ ) { //Take a small block of window size in the filtered images x_block = Ix.block( i-hw, j-hw, win_sz, win_sz); y_block = Iy.block( i-hw, j-hw, win_sz, win_sz); t_block = It.block( i-hw, j-hw, win_sz, win_sz); //Convert these blocks in vectors Map<Derived> A1( x_block.data(), win_sz*win_sz, 1); Map<Derived> A2( y_block.data(), win_sz*win_sz, 1); Map<Derived> B( t_block.data(), win_sz*win_sz, 1); //Organize the vectors in a matrix A = Derived( win_sz*win_sz, 2 ); A.block(0, 0, win_sz*win_sz, 1) = A1; A.block(0, 1, win_sz*win_sz, 1) = A2; //Solve the linear least square system solutions = (A.transpose() * A).ldlt().solve(A.transpose() * B); //Insert the solutions in the optical flow matrices uv[0](i, j) = solutions(0); uv[1](i, j) = solutions(1); } } return uv; }
inline Derived migrate(client_base<Derived, Stub> const& to_migrate, naming::id_type const& target_storage) { typedef typename client_base<Derived, Stub>::server_component_type component_type; return Derived(migrate<component_type>(to_migrate.get_gid(), target_storage)); }
static optional get_by_value(value_type value) { for(index_type i = 0; i < Derived::size; ++i) { typedef boost::optional<value_type> optional_value; optional_value cur = Derived::values(enum_cast<Derived>(i)); if(value == *cur) return Derived(enum_cast<Derived>(i)); } return optional(); }
Derived copy(client_base<Derived, Stub> const& to_copy, naming::id_type const& target_locality = naming::invalid_id) { typedef typename client_base<Derived, Stub>::server_component_type component_type; typedef server::copy_component_action<component_type> action_type; id_type id = to_copy.get_id(); return Derived(hpx::detail::async_colocated<action_type>( to_copy, to_copy, target_locality)); }
namespace yapg { template<class Derived> class Singleton { public: static Derived& getInstance() { return instance; } protected: Singleton() {}; private: static Derived instance; }; template<class Derived> Derived Singleton<Derived>::instance = Derived(); }
const Derived operator/(const HistoBase<x_value_type, y_value_type, Derived>& lhs, const y_value_type& scalar) { return Derived(lhs) /= scalar; }
const Derived operator*(const y_value_type& scalar, const HistoBase<x_value_type, y_value_type, Derived>& rhs) { return Derived(rhs) *= scalar; }
void testObj::test<7>(void) { const Derived d=Derived(); const Base &b=d; ensure("invalid type", strstr(ce_.getTypeName(b).c_str(), "Derived")!=NULL ); }
int main() { foo(Functor()); // match #1 foo(boost::function<void(int const&)>(Functor())); // match #2 foo(Base()); // match #3 foo(Derived()); // match #3 }
void foo(T const& f, typename T::result_type* = 0) { std::cout << "#1 " << BOOST_CURRENT_FUNCTION << std::endl; f(Derived()); f(10); }
inline friend Derived operator+(difference_type, traversal_base) { return Derived(); }
void test() { // This function tests C++0x 5.16 // p1 (contextually convert to bool) int i1 = ToBool() ? 0 : 1; // p2 (one or both void, and throwing) i1 ? throw 0 : throw 1; i1 ? test() : throw 1; i1 ? throw 0 : test(); i1 ? test() : test(); i1 = i1 ? throw 0 : 0; i1 = i1 ? 0 : throw 0; i1 ? 0 : test(); // expected-error {{right operand to ? is void, but left operand is of type 'int'}} i1 ? test() : 0; // expected-error {{left operand to ? is void, but right operand is of type 'int'}} (i1 ? throw 0 : i1) = 0; // expected-error {{expression is not assignable}} (i1 ? i1 : throw 0) = 0; // expected-error {{expression is not assignable}} // p3 (one or both class type, convert to each other) // b1 (lvalues) Base base; Derived derived; Convertible conv; Base &bar1 = i1 ? base : derived; Base &bar2 = i1 ? derived : base; Base &bar3 = i1 ? base : conv; Base &bar4 = i1 ? conv : base; // these are ambiguous BadBase bb; BadDerived bd; (void)(i1 ? bb : bd); // expected-error {{conditional expression is ambiguous; 'BadBase' can be converted to 'BadDerived' and vice versa}} (void)(i1 ? bd : bb); // expected-error {{conditional expression is ambiguous}} // curiously enough (and a defect?), these are not // for rvalues, hierarchy takes precedence over other conversions (void)(i1 ? BadBase() : BadDerived()); (void)(i1 ? BadDerived() : BadBase()); // b2.1 (hierarchy stuff) extern const Base constret(); extern const Derived constder(); // should use const overload A a1((i1 ? constret() : Base()).trick()); A a2((i1 ? Base() : constret()).trick()); A a3((i1 ? constret() : Derived()).trick()); A a4((i1 ? Derived() : constret()).trick()); // should use non-const overload i1 = (i1 ? Base() : Base()).trick(); i1 = (i1 ? Base() : Base()).trick(); i1 = (i1 ? Base() : Derived()).trick(); i1 = (i1 ? Derived() : Base()).trick(); // should fail: const lost (void)(i1 ? Base() : constder()); // expected-error {{incompatible operand types ('Base' and 'const Derived')}} (void)(i1 ? constder() : Base()); // expected-error {{incompatible operand types ('const Derived' and 'Base')}} Priv priv; Fin fin; (void)(i1 ? Base() : Priv()); // expected-error{{private base class}} (void)(i1 ? Priv() : Base()); // expected-error{{private base class}} (void)(i1 ? Base() : Fin()); // expected-error{{ambiguous conversion from derived class 'Fin' to base class 'Base':}} (void)(i1 ? Fin() : Base()); // expected-error{{ambiguous conversion from derived class 'Fin' to base class 'Base':}} (void)(i1 ? base : priv); // expected-error {{private base class}} (void)(i1 ? priv : base); // expected-error {{private base class}} (void)(i1 ? base : fin); // expected-error {{ambiguous conversion from derived class 'Fin' to base class 'Base':}} (void)(i1 ? fin : base); // expected-error {{ambiguous conversion from derived class 'Fin' to base class 'Base':}} // b2.2 (non-hierarchy) i1 = i1 ? I() : i1; i1 = i1 ? i1 : I(); I i2(i1 ? I() : J()); I i3(i1 ? J() : I()); // "the type [it] woud have if E2 were converted to an rvalue" vfn pfn = i1 ? F() : test; pfn = i1 ? test : F(); (void)(i1 ? A() : B()); // expected-error {{conversion from 'B' to 'A' is ambiguous}} (void)(i1 ? B() : A()); // expected-error {{conversion from 'B' to 'A' is ambiguous}} (void)(i1 ? 1 : Ambig()); // expected-error {{conversion from 'Ambig' to 'int' is ambiguous}} (void)(i1 ? Ambig() : 1); // expected-error {{conversion from 'Ambig' to 'int' is ambiguous}} // By the way, this isn't an lvalue: &(i1 ? i1 : i2); // expected-error {{address expression must be an lvalue or a function designator}} // p4 (lvalue, same type) Fields flds; int &ir1 = i1 ? flds.i1 : flds.i2; (i1 ? flds.b1 : flds.i2) = 0; (i1 ? flds.i1 : flds.b2) = 0; (i1 ? flds.b1 : flds.b2) = 0; // p5 (conversion to built-in types) // GCC 4.3 fails these double d1 = i1 ? I() : K(); pfn = i1 ? F() : G(); DFnPtr pfm; pfm = i1 ? DFnPtr() : &Base::fn1; pfm = i1 ? &Base::fn1 : DFnPtr(); // p6 (final conversions) i1 = i1 ? i1 : ir1; int *pi1 = i1 ? &i1 : 0; pi1 = i1 ? 0 : &i1; i1 = i1 ? i1 : EVal; i1 = i1 ? EVal : i1; d1 = i1 ? 'c' : 4.0; d1 = i1 ? 4.0 : 'c'; Base *pb = i1 ? (Base*)0 : (Derived*)0; pb = i1 ? (Derived*)0 : (Base*)0; pfm = i1 ? &Base::fn1 : &Derived::fn2; pfm = i1 ? &Derived::fn2 : &Base::fn1; pfm = i1 ? &Derived::fn2 : 0; pfm = i1 ? 0 : &Derived::fn2; const int (MixedFieldsDerived::*mp1) = i1 ? &MixedFields::ci : &MixedFieldsDerived::i; const volatile int (MixedFields::*mp2) = i1 ? &MixedFields::ci : &MixedFields::cvi; (void)(i1 ? &MixedFields::ci : &MixedFields::vi); // Conversion of primitives does not result in an lvalue. &(i1 ? i1 : d1); // expected-error {{address expression must be an lvalue or a function designator}} (void)&(i1 ? flds.b1 : flds.i1); // expected-error {{address of bit-field requested}} (void)&(i1 ? flds.i1 : flds.b1); // expected-error {{address of bit-field requested}} unsigned long test0 = 5; test0 = test0 ? (long) test0 : test0; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}} test0 = test0 ? (int) test0 : test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test0 = test0 ? (short) test0 : test0; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}} test0 = test0 ? test0 : (long) test0; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}} test0 = test0 ? test0 : (int) test0; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test0 = test0 ? test0 : (short) test0; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}} test0 = test0 ? test0 : (long) 10; test0 = test0 ? test0 : (int) 10; test0 = test0 ? test0 : (short) 10; test0 = test0 ? (long) 10 : test0; test0 = test0 ? (int) 10 : test0; test0 = test0 ? (short) 10 : test0; int test1; test0 = test0 ? EVal : test0; test1 = test0 ? EVal : (int) test0; test0 = test0 ? EVal : test1; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test0 = test0 ? test1 : EVal; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}} test1 = test0 ? EVal : (int) test0; test1 = test0 ? (int) test0 : EVal; // Note the thing that this does not test: since DR446, various situations // *must* create a separate temporary copy of class objects. This can only // be properly tested at runtime, though. }
friend Derived operator+(vector_ref_base const & lhs, size_t rhs) { return Derived(lhs.begin() + (std::min)(lhs.size(), rhs), lhs.end()); }
void bind_lvalue_to_rvalue() { Base &br1 = Base(); // expected-error{{non-const lvalue reference to type 'struct Base' cannot bind to a temporary of type 'struct Base'}} Base &br2 = Derived(); // expected-error{{non-const lvalue reference to type 'struct Base' cannot bind to a temporary of type 'struct Derived'}} int &ir = 17; // expected-error{{non-const lvalue reference to type 'int' cannot bind to a temporary of type 'int'}} }
void add_attributes( Eigen::MatrixBase<Derived> d, boost::ptr_vector< BaseAttribute >& t ) { add_attributes( typename Derived::Scalar(), t ); t.push_back( new Attribute<int>("rows", Derived().rows()) ); t.push_back( new Attribute<int>("columns", Derived().cols()) ); }
void create(size_t rows, size_t cols) { assert(((Derived*)this)->rows() == 0 && ((Derived*)this)->cols() == 0); ((Derived*)this)->operator=(Derived(rows, cols)); }
void OnMessage(const linear::Socket& socket, const linear::Message& msg) { const linear::Addrinfo& info = socket.GetPeerInfo(); switch(msg.type) { case linear::REQUEST: { linear::Request request = msg.as<linear::Request>(); std::cout << "recv Request: msgid = " << request.msgid << ", method = \"" << request.method << "\"" << ", params = " << request.params.stringify() << " from " << info.addr << ":" << info.port << std::endl; if (request.method == "echo") { std::cout << "do echo back: " << request.params.stringify() << std::endl; linear::Response response(request.msgid, request.params); response.Send(socket); } else { linear::Response response(request.msgid, linear::type::nil(), std::string("method not found")); response.Send(socket); } } break; case linear::RESPONSE: { linear::Response response = msg.as<linear::Response>(); std::cout << "recv Response: msgid = " << response.msgid << ", result = " << response.result.stringify() << ", error = " << response.error.stringify() << " from " << info.addr << ":" << info.port << std::endl; std::cout << "origin request: msgid = " << response.request.msgid << ", method = \"" << response.request.method << "\"" << ", params = " << response.request.params.stringify() << std::endl; } break; case linear::NOTIFY: { linear::Notify notify = msg.as<linear::Notify>(); std::cout << "recv Notify: " << "method = \"" << notify.method << "\"" << ", params = " << notify.params.stringify() << " from " << info.addr << ":" << info.port << std::endl; try { Derived data = notify.params.as<Derived>(); std::cout << "parameters detail" << std::endl; std::cout << "Base::" << "int: " << data.base_val.int_val << ", double: " << data.base_val.double_val << ", string: " << data.base_val.string_val << ", vector: " << data.base_val.vector_val[0] << ", map: {\"key\": " << data.base_val.map_val["key"] << "}" << std::endl; std::cout << "Derived::int: " << data.derived_val << std::endl; } catch(const std::bad_cast&) { std::cout << "invalid type cast" << std::endl; } linear::Notify notify_from_server("from server", Derived()); notify_from_server.Send(LINEAR_BROADCAST_GROUP); // send notify to all connected clients } break; default: { std::cout << "BUG: plz inform to linear-developpers" << std::endl; } break; } }
const Derived operator/(const HistoBase<x_value_type, y_value_type, Derived>& lhs, const HistoBase<x_value_type, y_value_type, Derived>& rhs) { return Derived(lhs) /= rhs; }
inline constexpr friend Derived operator+(const Derived &d, T c) { return Derived(d._id + static_cast<uint64_t>(c)); }
int main(int argc, char* argv[]) { #if _WIN32 linear::log::SetLevel(linear::log::LOG_DEBUG); linear::log::EnableStderr(); std::string host = (argc > 1) ? std::string(argv[1]) : "127.0.0.1"; int port = (argc > 2) ? atoi(argv[2]) : 37800; #else bool show_log = false; linear::log::Level level = linear::log::LOG_OFF; int ch, lv; extern char* optarg; extern int optind; while ((ch = getopt(argc, argv, "hl:")) != -1) { switch(ch) { case 'h': usage(argv[0]); return 0; case 'l': show_log = true; lv = atoi(optarg); lv = (lv < 0) ? 0 : ((lv > 4) ? 4 : lv); level = static_cast<linear::log::Level>(lv); break; default: break; } } argc -= optind; argv += optind; if (show_log) { linear::log::SetLevel(level); linear::log::EnableStderr(); } std::string host = (argc >= 1) ? std::string(argv[0]) : "127.0.0.1"; int port = (argc >= 2) ? atoi(argv[1]) : 37800; #endif linear::shared_ptr<ApplicationHandler> handler = linear::shared_ptr<ApplicationHandler>(new ApplicationHandler()); linear::WSSClient client = linear::WSSClient(handler); linear::SSLContext ssl_context(linear::SSLContext::TLSv1_1_client); ssl_context.SetVerifyMode(linear::SSLContext::VERIFY_NONE); linear::WSRequestContext ws_context; ws_context.path = "linear"; ws_context.query = "?hoge=foo&alice=bob"; linear::WSSSocket socket= client.CreateSocket(host, port, ws_context, ssl_context);; std::string cmd; std::cout << "Commands: connect, disconnect, echo, notify, exit" << std::endl; std::getline(std::cin, cmd); while (true) { if (cmd == "connect") { handler->SetNumOfRetry(3); linear::Error err = socket.Connect(); if (err.Code() != linear::LNR_OK) { std::cout << err.Message() << std::endl; } } else if (cmd == "disconnect") { handler->SetNumOfRetry(0); linear::Error err = socket.Disconnect(); if (err.Code() != linear::LNR_OK) { std::cout << err.Message() << std::endl; } } else if (cmd == "echo") { std::string data; std::cout << "A Response will be received by ApplicationHandler::OnMessage asynchronously" << std::endl; std::cout << "Input some words: " << std::endl; std::getline(std::cin, data); linear::Request req(cmd, data); std::cout << "msgid: " << req.msgid << std::endl; linear::Error err = req.Send(socket, 3000); if (err.Code() != linear::LNR_OK) { std::cout << err.Message() << std::endl; } } else if (cmd == "notify") { linear::Notify notify("from client", Derived()); linear::Error err = notify.Send(socket); if (err.Code() != linear::LNR_OK) { std::cout << err.Message() << std::endl; } } else if (cmd == "exit") { break; } std::getline(std::cin, cmd); } return 0; }
struct Derived: Base { Derived() : Base(42) { static_assert(!noexcept(Derived()), "Err"); } };
HPX_FORCEINLINE static Derived create(SharedState* shared_state) { return Derived(future<id_type>( boost::intrusive_ptr<SharedState>(shared_state))); }
// First, the straightforward functions: ITERATOR_TEST_SECTION_DEFAULT_CTOR(ci) ITERATOR_TEST_SECTION_BASE(ci, int) ITERATOR_TEST_SECTION_COPY_ASSIGNMENT(ci, int) ITERATOR_TEST_SECTION_EQUALITY(ci, int) ITERATOR_TEST_SECTION_INCREMENT(ci, int) ITERATOR_TEST_SECTION_DECREMENT(ci, int) ITERATOR_TEST_SECTION_PLUS_MINUS(ci, int) ITERATOR_TEST_SECTION_LESS(ci, int) // now the "special" operators * and -> and []: SECTION("dereference", "*a; a->m; a[n]") { auto d1 = Derived(42); Base* pb = &d1; auto iter = apf::cast_iterator<Derived, Base**>(&pb); Derived d2 = *iter; Derived d3 = iter[0]; CHECK(d2._n == 42); CHECK(iter->_n == 42); CHECK(d3._n == 42); iter->_n = 23; CHECK(d1._n == 23); (*iter)._n = 42;
inline static constexpr Derived min() { return Derived(std::numeric_limits<uint64_t>::max()); }