Just a quick question about the async_accept() in acceptor. Must the accept_handler be declared as a static member function within my class? The online examples do not seem to do this at all, and if I try it without the static keyword on my private member function then the compiler complains about it not matching the signature. Etienne Pretorius
Hello List, Just got home so now I can give out compiler errors: without 'static' I get this error: /usr/include/asio/detail/bind_handler.hpp: In member function ‘void asio::detail::binder1<Handler, Arg1>::operator()() [with Handler = void (something::other::service::*)(const asio::error_code&), Arg1 = asio::error_code]’ http://www.boost.org/doc/libs/1_36_0/doc/html/boost_asio/example/echo/async_... class server { public: ... ... void handle_accept(session* new_session, const boost::system::error_code& error) { I see no static declaration. Any hints? Etienne Pretorius
I'm having a hard time trying to understand meta-programming. I have a template class template<class CDB> struct MyClass { template<class CDB0, class CDB1> typedef MyClass<mpl::transform<CDB0, CDB1, mpl::or<_1, _2> > > Or; template<class CDB0, class CDB1> friend Or<CDB0, CDB1> myOperation(MyClass<CDB0> &_r0, MyClass<CDB1> &_r1); }; The template argument will be of type mpl::vector_c<bool, arg0, arg1, ...> All the vectors will be of equal length. Now the function myOperation is supposed to iterate over both the vectors at the same time and do different operations depending on the value of both vectors at this position. I could generate a mpl::vector<std::pair<bool, bool>, ..> but I really don't know how. Any help would be appreciated. Peter
AMDG peter_foelsche@agilent.com wrote:
All the vectors will be of equal length. Now the function myOperation is supposed to iterate over both the vectors at the same time and do different operations depending on the value of both vectors at this position.
Look at zip_view <http://www.boost.org/doc/libs/1_36_0/libs/mpl/doc/refmanual/zip-view.html> and for_each <http://www.boost.org/doc/libs/1_36_0/libs/mpl/doc/refmanual/for-each.html>. In Christ, Steven Watanabe
<peter_foelsche <at> agilent.com> writes:
I'm having a hard time trying to understand meta-programming. I have a template class
snip
I could generate a mpl::vector<std::pair<bool, bool>, ..> but I really don't know how. Any help would be appreciated.
Peter
I'm happy to answer any MPL related questions, but I'm unclear as to what you're trying to accomplish. I'll be on IRC for a few more hours today, if you'd like to persue this on a medium that makes clarifying your problem a bit easier.
This code does not compile. I'm using Visual C++. Any help would be appreciated.
peter_foelsche wrote:
This code does not compile. I'm using Visual C++. Any help would be appreciated.
I'm still quite unclear as to what you're trying to accomplish, but the following compiles: #include <utility> #include <boost/mpl/placeholders.hpp> #include <boost/mpl/back.hpp> #include <boost/mpl/for_each.hpp> #include <boost/mpl/front.hpp> #include <boost/mpl/or.hpp> #include <boost/mpl/transform.hpp> #include <boost/mpl/vector.hpp> #include <boost/mpl/zip_view.hpp> #include <boost/noncopyable.hpp> namespace mpl = boost::mpl; template<typename T> struct wrap { }; template<typename CDB> struct CDer { }; template<typename CDB, typename CDB1> struct CMyOperation : private boost::noncopyable { typedef CDer < typename mpl::transform<CDB, CDB1, mpl::or_<mpl::_1, mpl::_2> >::type > CDerOr; CMyOperation(CDer<CDB> const& r0, CDer<CDB1> const& r1, CDerOr& rT) : m_r0(r0), m_r1(r1), m_rT(rT), m_iPos(0) { } void operator ()(std::pair<bool, bool> const&) { ++m_iPos; } private: CDer<CDB> const& m_r0; CDer<CDB1> const& m_r1; CDerOr& m_rT; unsigned m_iPos; }; template<typename CDB, typename CDB1> struct CCreatePair { CCreatePair(CMyOperation<CDB, CDB1>& op) : m_sOp(&op) { } typedef void result_type; template<typename T> void operator ()(wrap<T>) const { typedef typename mpl::front<T>::type first; typedef typename mpl::back<T>::type second; (*m_sOp)(std::make_pair(first::value, second::value)); } private: CMyOperation<CDB, CDB1>* m_sOp; }; template<typename CDB, typename CDB1> typename CMyOperation<CDB, CDB1>::CDerOr myOperation(CDer<CDB> const& _r0, CDer<CDB1> const& _r1) { typedef mpl::zip_view<mpl::vector<CDB, CDB1> > CMerged; typename CMyOperation<CDB, CDB1>::CDerOr sRet; CMyOperation<CDB, CDB1> sOp(_r0, _r1, sRet); CCreatePair<CDB, CDB1> createPair(sOp); mpl::for_each<CMerged, wrap<mpl::_1> >(createPair); return sRet; } int main() { CDer<mpl::vector<mpl::true_, mpl::true_> > sDer0; CDer<mpl::vector<mpl::false_, mpl::true_> > sDer1; myOperation(sDer0, sDer1); return 0; }
Etienne Philip Pretorius wrote:
Hello List,
Just got home so now I can give out compiler errors:
without 'static' I get this error:
/usr/include/asio/detail/bind_handler.hpp: In member function ‘void asio::detail::binder1<Handler, Arg1>::operator()() [with Handler = void (something::other::service::*)(const asio::error_code&), Arg1 = asio::error_code]’
http://www.boost.org/doc/libs/1_36_0/doc/html/boost_asio/example/echo/async_...
class server { public: ... ... void handle_accept(session* new_session, const boost::system::error_code& error) {
I see no static declaration.
Any hints?
Etienne Pretorius _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Are the example and header file the same version?
Sorry to rehash an old thread, I must be only person that just can not get this to work.... here is my build output: /usr/bin/make -f nbproject/Makefile-Debug.mk SUBPROJECTS= .build-conf make[1]: Entering directory `/home/etienne/NetBeansProjects/mingle' mkdir -p build/Debug/GNU-Linux-x86 g++ -c -g -o build/Debug/GNU-Linux-x86/main.o main.cc mkdir -p build/Debug/GNU-Linux-x86 g++ -c -g -o build/Debug/GNU-Linux-x86/server.o server.cc mkdir -p build/Debug/GNU-Linux-x86 g++ -c -g -o build/Debug/GNU-Linux-x86/client.o client.cc mkdir -p dist/Debug/GNU-Linux-x86 g++ -o dist/Debug/GNU-Linux-x86/mingle build/Debug/GNU-Linux-x86/main.o build/Debug/GNU-Linux-x86/server.o build/Debug/GNU-Linux-x86/client.o -lpthread build/Debug/GNU-Linux-x86/server.o: In function `mingle::server::accept()': /home/etienne/NetBeansProjects/mingle/server.cc:36: undefined reference to `mingle::server::handle_accept(mingle::client*, asio::error_code const&)' collect2: ld returned 1 exit status make[1]: *** [dist/Debug/GNU-Linux-x86/mingle] Error 1 make[1]: Leaving directory `/home/etienne/NetBeansProjects/mingle' make: *** [.build-impl] Error 2 Build failed. Exit value 2. Here is the code that complains: void server::accept( ){ client* connection = new client( acceptor_.io_service()); client_.push_back(connection); acceptor_.async_accept(connection->socket(), boost::bind(&mingle::server::handle_accept, this,connection,asio::placeholders::error)); };//accept void handle_accept( client* connection, const asio::error_code& ec ) { };//handle_accept The header file: namespace mingle { class server { public: server( asio::io_service&, short ); ~server() throw(); private: void accept(); void handle_accept( client*, const asio::error_code& ); std::vector<client*> client_; asio::ip::tcp::acceptor acceptor_; protected: }; }; Now why would the linker of all things complain that it just can not find the handle_accept method? I modeled it after the online examples with one adjustment - the client is not a Meyer's singleton like class. Packaged information: Package: libasio-dev Priority: optional Section: universe/devel Installed-Size: 1404 Maintainer: Ubuntu MOTU Developers <ubuntu-motu@lists.ubuntu.com> Original-Maintainer: Simon Richter <sjr@debian.org> Architecture: all Source: asio Version: 0.3.8~rc3-2 Depends: libboost-dev Recommends: libssl-dev Filename: pool/universe/a/asio/libasio-dev_0.3.8~rc3-2_all.deb Size: 149402 MD5sum: fe9a5519552f5d2703238e18c85a5acb SHA1: 09fc70379b840dbba1654544b9299d11c39a6edb SHA256: 38d69bbb72ea825c8be711e407b56bc871d97d6b29693ede3a6ac05f55edc925 Description: cross-platform C++ library for network programming asio is a cross-platform C++ library for network programming that provides developers with a consistent asynchronous I/O model using a modern C++ approach. It has recently been accepted into Boost. . This package contains the development header files. Bugs: mailto:ubuntu-users@lists.ubuntu.com Origin: Ubuntu Thank you, Etienne Pretorius
Sorry, Please ignore the last post.... I am missed the fact that it is not part of a class.... I need to rest. Apologetic, Etienne Pretorius
participants (5)
-
Adam Merz
-
Etienne Philip Pretorius
-
peter_foelsche@agilent.com
-
Steven Watanabe
-
sun.aries