I have a header file called transaction_gen.h and a corresponding cpp file called transaction_gen.cpp.
Here is what I have in transaction_gen.h
#ifndef BITCOIN_TEST_GEN_TRANSACTION_GEN_H
#define BITCOIN_TEST_GEN_TRANSACTION_GEN_H
#include <rapidcheck/gen/Arbitrary.h>
#include <rapidcheck/Gen.h>
#include "primitives/transaction.h"
#include "script/script.h"
#include "amount.h"
#include "test/gen/script_gen.h"
#include "test/gen/crypto_gen.h"
namespace rc {
template<>
struct Arbitrary<COutPoint> {
static Gen<COutPoint> arbitrary() {
return gen::map(gen::tuple(gen::arbitrary<uint256>(), gen::arbitrary<uint32_t>()), [](std::tuple<uint256, uint32_t> outPointPrimitives) {
uint32_t nIn;
uint256 nHashIn;
std::tie(nHashIn, nIn) = outPointPrimitives;
return COutPoint(nHashIn, nIn);
});
};
};
template<>
struct Arbitrary<CTxIn> {
static Gen<CTxIn> arbitrary() {
return gen::map(gen::tuple(gen::arbitrary<COutPoint>(), gen::arbitrary<CScript>(), gen::arbitrary<uint32_t>()), [](std::tuple<COutPoint, CScript, uint32_t> txInPrimitives) {
COutPoint outpoint;
CScript script;
uint32_t sequence;
std::tie(outpoint,script,sequence) = txInPrimitives;
return CTxIn(outpoint,script,sequence);
});
};
};
/** Generates one or more inputs */
Gen<std::vector<CTxIn>> oneOrMoreInputs();
template<>
struct Arbitrary<CAmount> {
static Gen<CAmount> arbitrary() {
//why doesn't this generator call work? It seems to cause an infinite loop.
//return gen::arbitrary<int64_t>();
return gen::inRange(std::numeric_limits<int64_t>::min(),std::numeric_limits<int64_t>::max());
};
};
template<>
struct Arbitrary<CTxOut> {
static Gen<CTxOut> arbitrary() {
return gen::map(gen::tuple(gen::arbitrary<CAmount>(), gen::arbitrary<CScript>()), [](std::tuple<CAmount, CScript> txOutPrimitives) {
CAmount amount;
CScript script;
std::tie(amount,script) = txOutPrimitives;
return CTxOut(amount,script);
});
};
};
and here is what I have in the corresponding cpp file
#include <rapidcheck/gen/Arbitrary.h>
#include <rapidcheck/Gen.h>
#include "primitives/transaction.h"
#include "script/script.h"
#include "amount.h"
#include "test/gen/transaction_gen.h"
namespace rc {
/** Generates one or more inputs */
Gen<std::vector<CTxIn>> oneOrMoreInputs() {
return gen::suchThat(gen::arbitrary<std::vector<CTxIn>>(), [](std::vector<CTxIn> vin) {
return vin.size() > 0;
});
}
/** Generates one or more outputs */
Gen<std::vector<CTxOut>> oneOrMoreOutputs() {
return gen::suchThat(gen::arbitrary<std::vector<CTxOut>>(), [](std::vector<CTxOut> vout) {
return vout.size() > 0;
});
}
}
and this will compile fine when I build my program.
However, since I want to be using functionality located in transaction_gen.h I obviously want to include it in my program. However, when I include it I get a long nasty error message:
chris#chris-870Z5E-880Z5E-680Z5E:~/.../src/test$ make
make -C .. bitcoin_test
make[1]: Entering directory `/home/chris/dev/bitcoin/src'
CXX test/test_test_bitcoin-transaction_properties.o
CXX test/gen/test_test_bitcoin-transaction_gen.o
In file included from ./test/gen/script_gen.h:6:0,
from ./test/gen/transaction_gen.h:9,
from test/gen/transaction_gen.cpp:8:
./test/gen/crypto_gen.h: In static member function ‘static rc::Gen<CKey> rc::Arbitrary<CKey>::arbitrary()’:
./test/gen/crypto_gen.h:19:8: error: no matching function for call to ‘map(rc::Arbitrary<CKey>::arbitrary()::<lambda(int)>)’
});
^
In file included from /usr/local/include/rapidcheck/Gen.h:74:0,
from /usr/local/include/rapidcheck/gen/Arbitrary.h:3,
from test/gen/transaction_gen.cpp:1:
/usr/local/include/rapidcheck/Gen.hpp:15:54: note: candidate: template<class T, class Mapper> rc::Gen<typename std::decay<typename std::result_of<Mapper(T)>::type>::type> rc::gen::map(rc::Gen<T>, Mapper&&)
Gen<Decay<typename std::result_of<Mapper(T)>::type>> map(Gen<T> gen,
^
/usr/local/include/rapidcheck/Gen.hpp:15:54: note: template argument deduction/substitution failed:
In file included from ./test/gen/script_gen.h:6:0,
from ./test/gen/transaction_gen.h:9,
from test/gen/transaction_gen.cpp:8:
./test/gen/crypto_gen.h:19:8: note: candidate expects 2 arguments, 1 provided
});
^
./test/gen/crypto_gen.h: In static member function ‘static rc::Gen<std::vector<unsigned char, secure_allocator<unsigned char> > > rc::Arbitrary<std::vector<unsigned char, secure_allocator<unsigned char> > >::arbitrary()’:
./test/gen/crypto_gen.h:29:8: error: no matching function for call to ‘map(rc::Arbitrary<std::vector<unsigned char, secure_allocator<unsigned char> > >::arbitrary()::<lambda(CKey)>)’
});
^
In file included from /usr/local/include/rapidcheck/Gen.h:74:0,
from /usr/local/include/rapidcheck/gen/Arbitrary.h:3,
from test/gen/transaction_gen.cpp:1:
/usr/local/include/rapidcheck/Gen.hpp:15:54: note: candidate: template<class T, class Mapper> rc::Gen<typename std::decay<typename std::result_of<Mapper(T)>::type>::type> rc::gen::map(rc::Gen<T>, Mapper&&)
Gen<Decay<typename std::result_of<Mapper(T)>::type>> map(Gen<T> gen,
^
/usr/local/include/rapidcheck/Gen.hpp:15:54: note: template argument deduction/substitution failed:
In file included from ./test/gen/script_gen.h:6:0,
from ./test/gen/transaction_gen.h:9,
from test/gen/transaction_gen.cpp:8:
./test/gen/crypto_gen.h:29:8: note: candidate expects 2 arguments, 1 provided
});
^
./test/gen/crypto_gen.h: In static member function ‘static rc::Gen<CPubKey> rc::Arbitrary<CPubKey>::arbitrary()’:
./test/gen/crypto_gen.h:39:8: error: no matching function for call to ‘map(rc::Arbitrary<CPubKey>::arbitrary()::<lambda(CKey)>)’
});
^
In file included from /usr/local/include/rapidcheck/Gen.h:74:0,
from /usr/local/include/rapidcheck/gen/Arbitrary.h:3,
from test/gen/transaction_gen.cpp:1:
/usr/local/include/rapidcheck/Gen.hpp:15:54: note: candidate: template<class T, class Mapper> rc::Gen<typename std::decay<typename std::result_of<Mapper(T)>::type>::type> rc::gen::map(rc::Gen<T>, Mapper&&)
Gen<Decay<typename std::result_of<Mapper(T)>::type>> map(Gen<T> gen,
^
/usr/local/include/rapidcheck/Gen.hpp:15:54: note: template argument deduction/substitution failed:
In file included from ./test/gen/script_gen.h:6:0,
from ./test/gen/transaction_gen.h:9,
from test/gen/transaction_gen.cpp:8:
./test/gen/crypto_gen.h:39:8: note: candidate expects 2 arguments, 1 provided
});
^
./test/gen/crypto_gen.h: In static member function ‘static rc::Gen<uint256> rc::Arbitrary<uint256>::arbitrary()’:
./test/gen/crypto_gen.h:49:8: error: no matching function for call to ‘map(rc::Arbitrary<uint256>::arbitrary()::<lambda(int)>)’
});
^
In file included from /usr/local/include/rapidcheck/Gen.h:74:0,
from /usr/local/include/rapidcheck/gen/Arbitrary.h:3,
from test/gen/transaction_gen.cpp:1:
/usr/local/include/rapidcheck/Gen.hpp:15:54: note: candidate: template<class T, class Mapper> rc::Gen<typename std::decay<typename std::result_of<Mapper(T)>::type>::type> rc::gen::map(rc::Gen<T>, Mapper&&)
Gen<Decay<typename std::result_of<Mapper(T)>::type>> map(Gen<T> gen,
^
/usr/local/include/rapidcheck/Gen.hpp:15:54: note: template argument deduction/substitution failed:
In file included from ./test/gen/script_gen.h:6:0,
from ./test/gen/transaction_gen.h:9,
from test/gen/transaction_gen.cpp:8:
./test/gen/crypto_gen.h:49:8: note: candidate expects 2 arguments, 1 provided
});
^
In file included from /usr/local/include/rapidcheck/gen/Arbitrary.h:22:0,
from test/gen/transaction_gen.cpp:1:
/usr/local/include/rapidcheck/gen/Arbitrary.hpp: In instantiation of ‘struct rc::Arbitrary<std::vector<unsigned char> >’:
/usr/local/include/rapidcheck/gen/Arbitrary.h:17:33: required by substitution of ‘template<class T> decltype (rc::Arbitrary<T>::arbitrary()) rc::gen::arbitrary() [with T = std::vector<unsigned char>]’
./test/gen/script_gen.h:13:66: required from here
/usr/local/include/rapidcheck/gen/Arbitrary.hpp:22:62: error: incomplete type ‘rc::gen::detail::DefaultArbitrary<std::vector<unsigned char> >’ used in nested name specifier
static decltype(gen::detail::DefaultArbitrary<T>::arbitrary()) arbitrary() {
^
In file included from ./test/gen/transaction_gen.h:9:0,
from test/gen/transaction_gen.cpp:8:
./test/gen/script_gen.h: In static member function ‘static rc::Gen<CScript> rc::Arbitrary<CScript>::arbitrary()’:
./test/gen/script_gen.h:13:66: error: no matching function for call to ‘arbitrary()’
return gen::map(gen::arbitrary<std::vector<unsigned char>>(), [](std::vector<unsigned char> script) {
^
In file included from /usr/local/include/rapidcheck/gen/Arbitrary.h:22:0,
from test/gen/transaction_gen.cpp:1:
/usr/local/include/rapidcheck/gen/Arbitrary.hpp:13:37: note: candidate: template<class T> decltype (rc::Arbitrary<T>::arbitrary()) rc::gen::arbitrary()
decltype(Arbitrary<T>::arbitrary()) arbitrary() {
^
/usr/local/include/rapidcheck/gen/Arbitrary.hpp:13:37: note: substitution of deduced template arguments resulted in errors seen above
In file included from test/gen/transaction_gen.cpp:8:0:
./test/gen/transaction_gen.h: In static member function ‘static rc::Gen<COutPoint> rc::Arbitrary<COutPoint>::arbitrary()’:
./test/gen/transaction_gen.h:17:23: error: ‘tuple’ is not a member of ‘rc::gen’
return gen::map(gen::tuple(gen::arbitrary<uint256>(), gen::arbitrary<uint32_t>()), [](std::tuple<uint256, uint32_t> outPointPrimitives) {
^
./test/gen/transaction_gen.h:17:23: note: suggested alternative:
In file included from /usr/include/c++/5/bits/stl_algobase.h:64:0,
from /usr/include/c++/5/memory:62,
from /usr/local/include/rapidcheck/Seq.h:4,
from /usr/local/include/rapidcheck/Shrinkable.h:3,
from /usr/local/include/rapidcheck/Gen.h:4,
from /usr/local/include/rapidcheck/gen/Arbitrary.h:3,
from test/gen/transaction_gen.cpp:1:
/usr/include/c++/5/bits/stl_pair.h:83:11: note: ‘std::tuple’
class tuple;
^
In file included from /usr/local/include/rapidcheck/gen/Arbitrary.h:22:0,
from test/gen/transaction_gen.cpp:1:
/usr/local/include/rapidcheck/gen/Arbitrary.hpp: In instantiation of ‘struct rc::Arbitrary<unsigned int>’:
/usr/local/include/rapidcheck/gen/Arbitrary.h:17:33: required by substitution of ‘template<class T> decltype (rc::Arbitrary<T>::arbitrary()) rc::gen::arbitrary() [with T = unsigned int]’
./test/gen/transaction_gen.h:17:86: required from here
/usr/local/include/rapidcheck/gen/Arbitrary.hpp:22:62: error: incomplete type ‘rc::gen::detail::DefaultArbitrary<unsigned int>’ used in nested name specifier
static decltype(gen::detail::DefaultArbitrary<T>::arbitrary()) arbitrary() {
^
In file included from test/gen/transaction_gen.cpp:8:0:
./test/gen/transaction_gen.h:17:86: error: no matching function for call to ‘arbitrary()’
return gen::map(gen::tuple(gen::arbitrary<uint256>(), gen::arbitrary<uint32_t>()), [](std::tuple<uint256, uint32_t> outPointPrimitives) {
^
In file included from /usr/local/include/rapidcheck/gen/Arbitrary.h:22:0,
from test/gen/transaction_gen.cpp:1:
/usr/local/include/rapidcheck/gen/Arbitrary.hpp:13:37: note: candidate: template<class T> decltype (rc::Arbitrary<T>::arbitrary()) rc::gen::arbitrary()
decltype(Arbitrary<T>::arbitrary()) arbitrary() {
^
/usr/local/include/rapidcheck/gen/Arbitrary.hpp:13:37: note: substitution of deduced template arguments resulted in errors seen above
In file included from test/gen/transaction_gen.cpp:8:0:
./test/gen/transaction_gen.h: In static member function ‘static rc::Gen<CTxIn> rc::Arbitrary<CTxIn>::arbitrary()’:
./test/gen/transaction_gen.h:30:23: error: ‘tuple’ is not a member of ‘rc::gen’
return gen::map(gen::tuple(gen::arbitrary<COutPoint>(), gen::arbitrary<CScript>(), gen::arbitrary<uint32_t>()), [](std::tuple<COutPoint, CScript, uint32_t> txInPrimitives) {
^
./test/gen/transaction_gen.h:30:23: note: suggested alternative:
In file included from /usr/include/c++/5/bits/stl_algobase.h:64:0,
from /usr/include/c++/5/memory:62,
from /usr/local/include/rapidcheck/Seq.h:4,
from /usr/local/include/rapidcheck/Shrinkable.h:3,
from /usr/local/include/rapidcheck/Gen.h:4,
from /usr/local/include/rapidcheck/gen/Arbitrary.h:3,
from test/gen/transaction_gen.cpp:1:
/usr/include/c++/5/bits/stl_pair.h:83:11: note: ‘std::tuple’
class tuple;
^
In file included from test/gen/transaction_gen.cpp:8:0:
./test/gen/transaction_gen.h:30:115: error: no matching function for call to ‘arbitrary()’
return gen::map(gen::tuple(gen::arbitrary<COutPoint>(), gen::arbitrary<CScript>(), gen::arbitrary<uint32_t>()), [](std::tuple<COutPoint, CScript, uint32_t> txInPrimitives) {
^
In file included from /usr/local/include/rapidcheck/gen/Arbitrary.h:22:0,
from test/gen/transaction_gen.cpp:1:
/usr/local/include/rapidcheck/gen/Arbitrary.hpp:13:37: note: candidate: template<class T> decltype (rc::Arbitrary<T>::arbitrary()) rc::gen::arbitrary()
decltype(Arbitrary<T>::arbitrary()) arbitrary() {
^
/usr/local/include/rapidcheck/gen/Arbitrary.hpp:13:37: note: template argument deduction/substitution failed:
In file included from test/gen/transaction_gen.cpp:1:0:
/usr/local/include/rapidcheck/gen/Arbitrary.h: In substitution of ‘template<class T> decltype (rc::Arbitrary<T>::arbitrary()) rc::gen::arbitrary() [with T = unsigned int]’:
./test/gen/transaction_gen.h:30:115: required from here
/usr/local/include/rapidcheck/gen/Arbitrary.h:17:33: error: ‘arbitrary’ is not a member of ‘rc::Arbitrary<unsigned int>’
decltype(Arbitrary<T>::arbitrary()) arbitrary();
^
In file included from test/gen/transaction_gen.cpp:8:0:
./test/gen/transaction_gen.h: In static member function ‘static rc::Gen<long int> rc::Arbitrary<long int>::arbitrary()’:
./test/gen/transaction_gen.h:48:14: error: ‘inRange’ is not a member of ‘rc::gen’
return gen::inRange(std::numeric_limits<int64_t>::min(),std::numeric_limits<int64_t>::max());
^
./test/gen/transaction_gen.h: In static member function ‘static rc::Gen<CTxOut> rc::Arbitrary<CTxOut>::arbitrary()’:
./test/gen/transaction_gen.h:55:23: error: ‘tuple’ is not a member of ‘rc::gen’
return gen::map(gen::tuple(gen::arbitrary<CAmount>(), gen::arbitrary<CScript>()), [](std::tuple<CAmount, CScript> txOutPrimitives) {
^
./test/gen/transaction_gen.h:55:23: note: suggested alternative:
In file included from /usr/include/c++/5/bits/stl_algobase.h:64:0,
from /usr/include/c++/5/memory:62,
from /usr/local/include/rapidcheck/Seq.h:4,
from /usr/local/include/rapidcheck/Shrinkable.h:3,
from /usr/local/include/rapidcheck/Gen.h:4,
from /usr/local/include/rapidcheck/gen/Arbitrary.h:3,
from test/gen/transaction_gen.cpp:1:
/usr/include/c++/5/bits/stl_pair.h:83:11: note: ‘std::tuple’
class tuple;
^
test/gen/transaction_gen.cpp: In function ‘rc::Gen<std::vector<CTxIn> > rc::oneOrMoreInputs()’:
test/gen/transaction_gen.cpp:14:12: error: ‘suchThat’ is not a member of ‘rc::gen’
return gen::suchThat(gen::arbitrary<std::vector<CTxIn>>(), [](std::vector<CTxIn> vin) {
^
In file included from /usr/local/include/rapidcheck/gen/Arbitrary.h:22:0,
from test/gen/transaction_gen.cpp:1:
/usr/local/include/rapidcheck/gen/Arbitrary.hpp: In instantiation of ‘struct rc::Arbitrary<std::vector<CTxIn> >’:
/usr/local/include/rapidcheck/gen/Arbitrary.h:17:33: required by substitution of ‘template<class T> decltype (rc::Arbitrary<T>::arbitrary()) rc::gen::arbitrary() [with T = std::vector<CTxIn>]’
test/gen/transaction_gen.cpp:14:61: required from here
/usr/local/include/rapidcheck/gen/Arbitrary.hpp:22:62: error: incomplete type ‘rc::gen::detail::DefaultArbitrary<std::vector<CTxIn> >’ used in nested name specifier
static decltype(gen::detail::DefaultArbitrary<T>::arbitrary()) arbitrary() {
^
test/gen/transaction_gen.cpp:14:61: error: no matching function for call to ‘arbitrary()’
return gen::suchThat(gen::arbitrary<std::vector<CTxIn>>(), [](std::vector<CTxIn> vin) {
^
In file included from /usr/local/include/rapidcheck/gen/Arbitrary.h:22:0,
from test/gen/transaction_gen.cpp:1:
/usr/local/include/rapidcheck/gen/Arbitrary.hpp:13:37: note: candidate: template<class T> decltype (rc::Arbitrary<T>::arbitrary()) rc::gen::arbitrary()
decltype(Arbitrary<T>::arbitrary()) arbitrary() {
^
/usr/local/include/rapidcheck/gen/Arbitrary.hpp:13:37: note: substitution of deduced template arguments resulted in errors seen above
test/gen/transaction_gen.cpp: In function ‘rc::Gen<std::vector<CTxOut> > rc::oneOrMoreOutputs()’:
test/gen/transaction_gen.cpp:21:12: error: ‘suchThat’ is not a member of ‘rc::gen’
return gen::suchThat(gen::arbitrary<std::vector<CTxOut>>(), [](std::vector<CTxOut> vout) {
^
In file included from /usr/local/include/rapidcheck/gen/Arbitrary.h:22:0,
from test/gen/transaction_gen.cpp:1:
/usr/local/include/rapidcheck/gen/Arbitrary.hpp: In instantiation of ‘struct rc::Arbitrary<std::vector<CTxOut> >’:
/usr/local/include/rapidcheck/gen/Arbitrary.h:17:33: required by substitution of ‘template<class T> decltype (rc::Arbitrary<T>::arbitrary()) rc::gen::arbitrary() [with T = std::vector<CTxOut>]’
test/gen/transaction_gen.cpp:21:62: required from here
/usr/local/include/rapidcheck/gen/Arbitrary.hpp:22:62: error: incomplete type ‘rc::gen::detail::DefaultArbitrary<std::vector<CTxOut> >’ used in nested name specifier
static decltype(gen::detail::DefaultArbitrary<T>::arbitrary()) arbitrary() {
^
test/gen/transaction_gen.cpp:21:62: error: no matching function for call to ‘arbitrary()’
return gen::suchThat(gen::arbitrary<std::vector<CTxOut>>(), [](std::vector<CTxOut> vout) {
^
In file included from /usr/local/include/rapidcheck/gen/Arbitrary.h:22:0,
from test/gen/transaction_gen.cpp:1:
/usr/local/include/rapidcheck/gen/Arbitrary.hpp:13:37: note: candidate: template<class T> decltype (rc::Arbitrary<T>::arbitrary()) rc::gen::arbitrary()
decltype(Arbitrary<T>::arbitrary()) arbitrary() {
^
/usr/local/include/rapidcheck/gen/Arbitrary.hpp:13:37: note: substitution of deduced template arguments resulted in errors seen above
make[1]: *** [test/gen/test_test_bitcoin-transaction_gen.o] Error 1
make[1]: Leaving directory `/home/chris/dev/bitcoin/src'
make: *** [all] Error 2
and I'm not really sure why this is happening. It almost seems like when I include transaction_gen.h it erases all other header files I had included, this the problems like
In file included from ./test/gen/script_gen.h:6:0,
from ./test/gen/transaction_gen.h:9,
from test/gen/transaction_gen.cpp:8:
./test/gen/crypto_gen.h: In static member function ‘static rc::Gen<CKey> rc::Arbitrary<CKey>::arbitrary()’:
./test/gen/crypto_gen.h:19:8: error: no matching function for call to ‘map(rc::Arbitrary<CKey>::arbitrary()::<lambda(int)>)’
});
because this obviously is included properly when I exclude transaction_gen.h. Where am I going wrong here? I feel like this is a pretty simple fix but I've spent a couple hours on it now to avail :/
EDIT: I've pushed this up to github
Here is transaction_gen.h
Here is transaction_gen.cpp
Try remove these lines from transaction_gen.cpp:
#include <rapidcheck/gen/Arbitrary.h>
#include <rapidcheck/Gen.h>
#include "primitives/transaction.h"
#include "script/script.h"
#include "amount.h"
Keep this #include line only:
#include "test/gen/transaction_gen.h"
Your transaction_gen.h is missing a #endif at the end of the file.
Include these in your cpp file also
#include "test/gen/script_gen.h"
#include "test/gen/crypto_gen.h"
Related
Wrote short example: simple echo program. Please, help to compile this, because I don't understand why compiler error
I tried this: g++ -Wall -Wextra -pedantic client.cpp -o client -lboost_thread -lboost_system, but got next error https://pastebin.com/byevYxPa
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <string>
using namespace boost::asio;
using error_code = boost::system::error_code;
io_service ioservice;
posix::stream_descriptor out(ioservice, STDOUT_FILENO);
posix::stream_descriptor in(ioservice, STDIN_FILENO);
std::string line;
void on_read(const error_code & err, std::size_t bytes);
void on_write(const error_code & err, std::size_t bytes);
void on_read(const error_code & err, std::size_t bytes) {
if (err || line == "exit") return;
line += "\n";
async_write(out, buffer(line), on_write);
}
void on_write(const error_code & err, std::size_t bytes) {
write(out, buffer("$ "));
async_read_until(in, buffer(line),'\n',on_read);
}
int main() {
async_read_until(in, buffer(line),'\n',on_read);
ioservice.run();
}
I expected that this code will works correctly and will be compiled
client.cpp: In function ‘void on_read(const error_code&, std::size_t)’:
client.cpp:17:50: warning: unused parameter ‘bytes’ [-Wunused-parameter]
void on_read(const error_code & err, std::size_t bytes) {
^~~~~
client.cpp: In function ‘void on_write(const error_code&, std::size_t)’:
client.cpp:25:51: error: no matching function for call to ‘async_read_until(boost::asio::posix::stream_descriptor&, boost::asio::const_buffers_1, char, void (&)(const error_code&, std::size_t))’
async_read_until(in, buffer(line),'\n',on_read);
^
In file included from /usr/include/boost/asio/read_until.hpp:921:0,
from /usr/include/boost/asio.hpp:91,
from client.cpp:1:
/usr/include/boost/asio/impl/read_until.hpp:498:1: note: candidate: template<class AsyncReadStream, class Allocator, class ReadHandler> typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type boost::asio::async_read_until(AsyncReadStream&, boost::asio::basic_streambuf<Allocator>&, char, ReadHandler&&)
async_read_until(AsyncReadStream& s,
^~~~~~~~~~~~~~~~
/usr/include/boost/asio/impl/read_until.hpp:498:1: note: template argument deduction/substitution failed:
client.cpp:25:51: note: ‘boost::asio::const_buffers_1’ is not derived from ‘boost::asio::basic_streambuf<Allocator>’
async_read_until(in, buffer(line),'\n',on_read);
^
In file included from /usr/include/boost/asio/read_until.hpp:921:0,
from /usr/include/boost/asio.hpp:91,
from client.cpp:1:
/usr/include/boost/asio/impl/read_until.hpp:701:1: note: candidate: template<class AsyncReadStream, class Allocator, class ReadHandler> typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type boost::asio::async_read_until(AsyncReadStream&, boost::asio::basic_streambuf<Allocator>&, const string&, ReadHandler&&)
async_read_until(AsyncReadStream& s,
^~~~~~~~~~~~~~~~
/usr/include/boost/asio/impl/read_until.hpp:701:1: note: template argument deduction/substitution failed:
client.cpp:25:51: note: ‘boost::asio::const_buffers_1’ is not derived from ‘boost::asio::basic_streambuf<Allocator>’
async_read_until(in, buffer(line),'\n',on_read);
^
In file included from /usr/include/boost/asio/read_until.hpp:921:0,
from /usr/include/boost/asio.hpp:91,
from client.cpp:1:
/usr/include/boost/asio/impl/read_until.hpp:913:1: note: candidate: template<class AsyncReadStream, class Allocator, class ReadHandler> typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type boost::asio::async_read_until(AsyncReadStream&, boost::asio::basic_streambuf<Allocator>&, const regex&, ReadHandler&&)
async_read_until(AsyncReadStream& s,
^~~~~~~~~~~~~~~~
/usr/include/boost/asio/impl/read_until.hpp:913:1: note: template argument deduction/substitution failed:
client.cpp:25:51: note: ‘boost::asio::const_buffers_1’ is not derived from ‘boost::asio::basic_streambuf<Allocator>’
async_read_until(in, buffer(line),'\n',on_read);
^
In file included from /usr/include/boost/asio/read_until.hpp:921:0,
from /usr/include/boost/asio.hpp:91,
from client.cpp:1:
/usr/include/boost/asio/impl/read_until.hpp:1122:1: note: candidate: template<class AsyncReadStream, class Allocator, class MatchCondition, class ReadHandler> typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type boost::asio::async_read_until(AsyncReadStream&, boost::asio::basic_streambuf<Allocator>&, MatchCondition, ReadHandler&&, typename std::enable_if<boost::asio::is_match_condition<MatchCondition>::value>::type*)
async_read_until(AsyncReadStream& s,
^~~~~~~~~~~~~~~~
/usr/include/boost/asio/impl/read_until.hpp:1122:1: note: template argument deduction/substitution failed:
client.cpp:25:51: note: ‘boost::asio::const_buffers_1’ is not derived from ‘boost::asio::basic_streambuf<Allocator>’
async_read_until(in, buffer(line),'\n',on_read);
^
client.cpp:23:34: warning: unused parameter ‘err’ [-Wunused-parameter]
void on_write(const error_code & err, std::size_t bytes) {
^~~
client.cpp:23:51: warning: unused parameter ‘bytes’ [-Wunused-parameter]
void on_write(const error_code & err, std::size_t bytes) {
^~~~~
client.cpp: In function ‘int main()’:
client.cpp:29:51: error: no matching function for call to ‘async_read_until(boost::asio::posix::stream_descriptor&, boost::asio::const_buffers_1, char, void (&)(const error_code&, std::size_t))’
async_read_until(in, buffer(line),'\n',on_read);
^
In file included from /usr/include/boost/asio/read_until.hpp:921:0,
from /usr/include/boost/asio.hpp:91,
from client.cpp:1:
/usr/include/boost/asio/impl/read_until.hpp:498:1: note: candidate: template<class AsyncReadStream, class Allocator, class ReadHandler> typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type boost::asio::async_read_until(AsyncReadStream&, boost::asio::basic_streambuf<Allocator>&, char, ReadHandler&&)
async_read_until(AsyncReadStream& s,
^~~~~~~~~~~~~~~~
/usr/include/boost/asio/impl/read_until.hpp:498:1: note: template argument deduction/substitution failed:
client.cpp:29:51: note: ‘boost::asio::const_buffers_1’ is not derived from ‘boost::asio::basic_streambuf<Allocator>’
async_read_until(in, buffer(line),'\n',on_read);
^
In file included from /usr/include/boost/asio/read_until.hpp:921:0,
from /usr/include/boost/asio.hpp:91,
from client.cpp:1:
/usr/include/boost/asio/impl/read_until.hpp:701:1: note: candidate: template<class AsyncReadStream, class Allocator, class ReadHandler> typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type boost::asio::async_read_until(AsyncReadStream&, boost::asio::basic_streambuf<Allocator>&, const string&, ReadHandler&&)
async_read_until(AsyncReadStream& s,
^~~~~~~~~~~~~~~~
/usr/include/boost/asio/impl/read_until.hpp:701:1: note: template argument deduction/substitution failed:
client.cpp:29:51: note: ‘boost::asio::const_buffers_1’ is not derived from ‘boost::asio::basic_streambuf<Allocator>’
async_read_until(in, buffer(line),'\n',on_read);
^
In file included from /usr/include/boost/asio/read_until.hpp:921:0,
from /usr/include/boost/asio.hpp:91,
from client.cpp:1:
/usr/include/boost/asio/impl/read_until.hpp:913:1: note: candidate: template<class AsyncReadStream, class Allocator, class ReadHandler> typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type boost::asio::async_read_until(AsyncReadStream&, boost::asio::basic_streambuf<Allocator>&, const regex&, ReadHandler&&)
async_read_until(AsyncReadStream& s,
^~~~~~~~~~~~~~~~
/usr/include/boost/asio/impl/read_until.hpp:913:1: note: template argument deduction/substitution failed:
client.cpp:29:51: note: ‘boost::asio::const_buffers_1’ is not derived from ‘boost::asio::basic_streambuf<Allocator>’
async_read_until(in, buffer(line),'\n',on_read);
^
In file included from /usr/include/boost/asio/read_until.hpp:921:0,
from /usr/include/boost/asio.hpp:91,
from client.cpp:1:
/usr/include/boost/asio/impl/read_until.hpp:1122:1: note: candidate: template<class AsyncReadStream, class Allocator, class MatchCondition, class ReadHandler> typename boost::asio::async_result<typename boost::asio::handler_type<WriteHandler, void(boost::system::error_code, long unsigned int)>::type>::type boost::asio::async_read_until(AsyncReadStream&, boost::asio::basic_streambuf<Allocator>&, MatchCondition, ReadHandler&&, typename std::enable_if<boost::asio::is_match_condition<MatchCondition>::value>::type*)
async_read_until(AsyncReadStream& s,
^~~~~~~~~~~~~~~~
/usr/include/boost/asio/impl/read_until.hpp:1122:1: note: template argument deduction/substitution failed:
client.cpp:29:51: note: ‘boost::asio::const_buffers_1’ is not derived from ‘boost::asio::basic_streambuf<Allocator>’
async_read_until(in, buffer(line),'\n',on_read);
^
asio::buffer returns mutable buffer type, it doesn't match to the second param of async_read_until. This overload takes dynamic buffer, just use boost::asio::dynamic_buffer.
void on_write(const error_code & err, std::size_t bytes) {
write(out, buffer("$ "));
async_read_until(in, dynamic_buffer(line),'\n',on_read);
}
int main() {
async_read_until(in, dynamic_buffer(line),'\n',on_read);
ioservice.run();
}
LIVE demo
I need to recursively iterate through a directory; I got a pretty nice function for it from another thread here on SO; adapted it just a tiny bit for my purposes and it works perfectly on Mac with boost 1.62 and clang.
However, we're using SemaphoreCI (based on ubuntu 14.04 LTS and boost 1.54) and I just cannot get this to compile under those conditions.
#include <boost/algorithm/string/replace.hpp>
#include <boost/filesystem.hpp>
#include <boost/range.hpp>
void copyDirectoryRecursively(const fs::path& sourceDir, const fs::path& destinationDir)
{
if (!fs::exists(sourceDir) || !fs::is_directory(sourceDir))
{
throw std::runtime_error("Source directory " + sourceDir.string() + " does not exist or is not a directory");
}
if (!fs::create_directory(destinationDir) && !fs::exists(destinationDir))
{
throw std::runtime_error("Cannot create destination directory " + destinationDir.string());
}
for (const auto& dirEnt : fs::recursive_directory_iterator{sourceDir})
{
const auto& path = dirEnt.path();
auto relativePathStr = path.string();
boost::algorithm::replace_first(relativePathStr, sourceDir.string(), "");
try {
if (!fs::is_directory(path)) { fs::copy_file(path, destinationDir / relativePathStr); }
else { fs::copy_directory(path, destinationDir / relativePathStr); }
}
catch (...) {
throw std::runtime_error("Cannot copy file " + path.string() + ", because it already exists in the destination folder.");
}
}
}
Here's the error I'm getting,
GCC:
/home/runner/performous/game/fs.cc: In function ‘void copyDirectoryRecursively(const boost::filesystem::path&, const boost::filesystem::path&)’:
/home/runner/performous/game/fs.cc:74:73: error: no matching function for call to ‘begin(boost::filesystem::recursive_directory_iterator&)’
for (const auto& dirEnt : fs::recursive_directory_iterator{sourceDir})
^
/home/runner/performous/game/fs.cc:74:73: note: candidates are:
In file included from /usr/include/c++/4.8/string:51:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/boost/variant/variant.hpp:31,
from /home/runner/performous/game/configuration.hh:3,
from /home/runner/performous/game/fs.cc:2:
/usr/include/c++/4.8/bits/range_access.h:87:5: note: template<class _Tp, long unsigned int _Nm> _Tp* std::begin(_Tp (&)[_Nm])
^
/usr/include/c++/4.8/bits/range_access.h:87:5: note: template argument deduction/substitution failed:
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/bits/ios_base.h:41,
for (const auto& dirEnt : fs::recursive_directory_iterator{sourceDir})
from /usr/include/c++/4.8/ios:42,
from /usr/include/boost/variant/detail/move.hpp:22,
from /usr/include/c++/4.8/iterator:64,
from /usr/include/boost/variant/detail/initializer.hpp:23,
from /usr/include/c++/4.8/iterator:64,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/boost/variant.hpp:17,
begin(_Tp (&__arr)[_Nm])
from /usr/include/boost/variant/detail/move.hpp:22,
from /usr/include/boost/variant/detail/initializer.hpp:23,
from /usr/include/boost/variant/variant.hpp:31,
/home/runner/performous/game/fs.cc:74:73: note: mismatched types ‘_Tp [_Nm]’ and ‘boost::filesystem::recursive_directory_iterator’
from /usr/include/boost/variant.hpp:17,
^
In file included from /usr/include/c++/4.8/string:51:0,
from /home/runner/performous/game/configuration.hh:3,
from /home/runner/performous/game/fs.cc:2:
from /usr/include/c++/4.8/bits/locale_classes.h:40,
begin(const _Container& __cont) -> decltype(__cont.begin())
/usr/include/c++/4.8/bits/range_access.h:58:5: note: template<class _Container> decltype (__cont.begin()) std::begin(const _Container&)
/usr/include/c++/4.8/bits/range_access.h: In substitution of ‘template<class _Container> decltype (__cont.begin()) std::begin(const _Container&) [with _Container = boost::filesystem::recursive_directory_iterator]’:
/usr/include/c++/4.8/bits/range_access.h:58:5: note: template argument deduction/substitution failed:
from /usr/include/c++/4.8/bits/ios_base.h:41,
/home/runner/performous/game/fs.cc:74:73: required from here
/usr/include/c++/4.8/bits/range_access.h:58:5: error: ‘const class boost::filesystem::recursive_directory_iterator’ has no member named ‘begin’
from /usr/include/c++/4.8/ios:42,
/usr/include/c++/4.8/bits/range_access.h:48:5: note: template<class _Container> decltype (__cont.begin()) std::begin(_Container&)
begin(_Container& __cont) -> decltype(__cont.begin())
^
/usr/include/c++/4.8/bits/range_access.h: In substitution of ‘template<class _Container> decltype (__cont.begin()) std::begin(_Container&) [with _Container = boost::filesystem::recursive_directory_iterator]’:
/usr/include/c++/4.8/bits/range_access.h:48:5: error: ‘class boost::filesystem::recursive_directory_iterator’ has no member named ‘begin’
/home/runner/performous/game/fs.cc:74:73: required from here
from /usr/include/boost/config/no_tr1/utility.hpp:21,
In file included from /usr/include/c++/4.8/utility:74:0,
from /usr/include/boost/config/select_stdlib_config.hpp:37,
from /usr/include/boost/config.hpp:40,
^
from /usr/include/boost/variant/detail/config.hpp:16,
from /usr/include/boost/variant/variant.hpp:23,
from /usr/include/boost/variant.hpp:17,
from /home/runner/performous/game/configuration.hh:3,
/usr/include/c++/4.8/initializer_list:89:5: note: template<class _Tp> constexpr const _Tp* std::begin(std::initializer_list<_Tp>)
from /home/runner/performous/game/fs.cc:2:
begin(initializer_list<_Tp> __ils) noexcept
^
/usr/include/c++/4.8/bits/range_access.h:48:5: note: template argument deduction/substitution failed:
/usr/include/c++/4.8/initializer_list:89:5: note: template argument deduction/substitution failed:
/home/runner/performous/game/fs.cc:74:73: note: ‘boost::filesystem::recursive_directory_iterator’ is not derived from ‘std::initializer_list<_Tp>’
for (const auto& dirEnt : fs::recursive_directory_iterator{sourceDir})
/home/runner/performous/game/fs.cc:74:73: error: no matching function for call to ‘end(boost::filesystem::recursive_directory_iterator&)’
from /usr/include/c++/4.8/bits/locale_classes.h:40,
In file included from /usr/include/c++/4.8/string:51:0,
/home/runner/performous/game/fs.cc:74:73: note: candidates are:
from /usr/include/c++/4.8/iterator:64,
from /usr/include/c++/4.8/bits/ios_base.h:41,
^
from /usr/include/boost/variant/detail/move.hpp:22,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/ios:42,
from /usr/include/boost/variant/detail/initializer.hpp:23,
from /usr/include/boost/variant.hpp:17,
from /home/runner/performous/game/configuration.hh:3,
from /usr/include/boost/variant/variant.hpp:31,
/usr/include/c++/4.8/bits/range_access.h:97:5: note: template<class _Tp, long unsigned int _Nm> _Tp* std::end(_Tp (&)[_Nm])
from /home/runner/performous/game/fs.cc:2:
/usr/include/c++/4.8/bits/range_access.h:97:5: note: template argument deduction/substitution failed:
^
end(_Tp (&__arr)[_Nm])
/home/runner/performous/game/fs.cc:74:73: note: mismatched types ‘_Tp [_Nm]’ and ‘boost::filesystem::recursive_directory_iterator’
for (const auto& dirEnt : fs::recursive_directory_iterator{sourceDir})
^
In file included from /usr/include/c++/4.8/string:51:0,
from /usr/include/c++/4.8/bits/locale_classes.h:40,
from /usr/include/c++/4.8/bits/ios_base.h:41,
from /usr/include/c++/4.8/ios:42,
from /usr/include/c++/4.8/ostream:38,
from /usr/include/c++/4.8/iterator:64,
from /usr/include/boost/variant/detail/move.hpp:22,
from /usr/include/boost/variant.hpp:17,
from /usr/include/boost/variant/variant.hpp:31,
from /usr/include/boost/variant/detail/initializer.hpp:23,
from /home/runner/performous/game/configuration.hh:3,
from /home/runner/performous/game/fs.cc:2:
^
end(const _Container& __cont) -> decltype(__cont.end())
/usr/include/c++/4.8/bits/range_access.h:78:5: note: template<class _Container> decltype (__cont.end()) std::end(const _Container&)
/usr/include/c++/4.8/bits/range_access.h: In substitution of ‘template<class _Container> decltype (__cont.end()) std::end(const _Container&) [with _Container = boost::filesystem::recursive_directory_iterator]’:
/usr/include/c++/4.8/bits/range_access.h:78:5: note: template argument deduction/substitution failed:
/home/runner/performous/game/fs.cc:74:73: required from here
/usr/include/c++/4.8/bits/range_access.h:78:5: error: ‘const class boost::filesystem::recursive_directory_iterator’ has no member named ‘end’
end(_Container& __cont) -> decltype(__cont.end())
/usr/include/c++/4.8/bits/range_access.h:68:5: note: template<class _Container> decltype (__cont.end()) std::end(_Container&)
/usr/include/c++/4.8/bits/range_access.h:68:5: note: template argument deduction/substitution failed:
^/usr/include/c++/4.8/bits/range_access.h: In substitution of ‘template<class _Container> decltype (__cont.end()) std::end(_Container&) [with _Container = boost::filesystem::recursive_directory_iterator]’:
/home/runner/performous/game/fs.cc:74:73: required from here
/usr/include/c++/4.8/bits/range_access.h:68:5: error: ‘class boost::filesystem::recursive_directory_iterator’ has no member named ‘end’
In file included from /usr/include/c++/4.8/utility:74:0,
from /usr/include/boost/config/no_tr1/utility.hpp:21,
from /usr/include/boost/config/select_stdlib_config.hpp:37,
from /usr/include/boost/config.hpp:40,
from /usr/include/boost/variant/detail/config.hpp:16,
from /usr/include/boost/variant/variant.hpp:23,
from /usr/include/boost/variant.hpp:17,
from /home/runner/performous/game/configuration.hh:3,
from /home/runner/performous/game/fs.cc:2:
/usr/include/c++/4.8/initializer_list:99:5: note: template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)
end(initializer_list<_Tp> __ils) noexcept
^
/usr/include/c++/4.8/initializer_list:99:5: note: template argument deduction/substitution failed:
/home/runner/performous/game/fs.cc:74:73: note: ‘boost::filesystem::recursive_directory_iterator’ is not derived from ‘std::initializer_list<_Tp>’
for (const auto& dirEnt : fs::recursive_directory_iterator{sourceDir})
^
make[2]: *** [game/CMakeFiles/performous.dir/fs.cc.o] Error 1
make[1]: *** [game/CMakeFiles/performous.dir/all] Error 2
make: *** [all] Error 2
Clang:
/home/runner/performous/game/fs.cc:74:29: error: invalid range expression of
type 'boost::filesystem::recursive_directory_iterator'; no viable 'begin'
function available
for (const auto& dirEnt : fs::recursive_directory_iterator{sourceDir})
^ ~~
1 error generated.
make[2]: *** [game/CMakeFiles/performous.dir/fs.cc.o] Error 1
make[1]: *** [game/CMakeFiles/performous.dir/all] Error 2
make: *** [all] Error 2
Back then, the iterator didn't model the range concept. So, just make your own range:
for (const auto& dirEnt : boost::make_iterator_range(fs::recursive_directory_iterator{sourceDir}, {})) {
See it Live On GCC 4.8 and Boost 1.54
I am trying to replicate tensorflow serving examples from https://tensorflow.github.io/serving/serving_advanced.html
But I get following error. It is possibly Tensorflow library error. Any help will be greatly appreciated.
:
~/serving$ bazel build //tensorflow_serving/example:mnist_inference_2
INFO: Found 1 target...
ERROR: /home/ubuntu/serving/tensorflow_serving/session_bundle/BUILD:125:1: C++ compilation of rule '//tensorflow_serving/session_bundle:session_bundle' failed: gcc failed: error executing command /usr/bin/gcc -U_FORTIFY_SOURCE '-D_FORTIFY_SOURCE=1' -fstack-protector -Wall -Wl,-z,-relro,-z,now -Wunused-but-set-parameter -Wno-free-nonheap-object -fno-omit-frame-pointer '-std=c++0x' -iquote . ... (remaining 103 argument(s) skipped): com.google.devtools.build.lib.shell.BadExitStatusException: Process exited with status 1.
In file included from ./tensorflow_serving/session_bundle/session_bundle.h:30:0,
from tensorflow_serving/session_bundle/session_bundle.cc:16:
./tensorflow_serving/session_bundle/signature.h:40:22: error: 'Signatures' has not been declared
Signatures* signatures);
^
./tensorflow_serving/session_bundle/signature.h:43:28: error: 'Signatures' does not name a type
Status SetSignatures(const Signatures& signatures,
^
./tensorflow_serving/session_bundle/signature.h:43:40: error: ISO C++ forbids declaration of 'signatures' with no type [-fpermissive]
Status SetSignatures(const Signatures& signatures,
^
./tensorflow_serving/session_bundle/signature.h:51:5: error: 'ClassificationSignature' has not been declared
ClassificationSignature* signature);
^
./tensorflow_serving/session_bundle/signature.h:58:5: error: 'ClassificationSignature' has not been declared
ClassificationSignature* signature);
^
./tensorflow_serving/session_bundle/signature.h:64:31: error: 'RegressionSignature' has not been declared
RegressionSignature* signature);
^
./tensorflow_serving/session_bundle/signature.h:73:32: error: 'ClassificationSignature' does not name a type
Status RunClassification(const ClassificationSignature& signature,
^
./tensorflow_serving/session_bundle/signature.h:73:57: error: ISO C++ forbids declaration of 'signature' with no type [-fpermissive]
Status RunClassification(const ClassificationSignature& signature,
^
./tensorflow_serving/session_bundle/signature.h:83:28: error: 'RegressionSignature' does not name a type
Status RunRegression(const RegressionSignature& signature, const Tensor& input,
^
./tensorflow_serving/session_bundle/signature.h:83:49: error: ISO C++ forbids declaration of 'signature' with no type [-fpermissive]
Status RunRegression(const RegressionSignature& signature, const Tensor& input,
^
./tensorflow_serving/session_bundle/signature.h:90:28: error: 'GenericSignature' has not been declared
GenericSignature* signature);
^
./tensorflow_serving/session_bundle/signature.h:94:28: error: 'Signature' has not been declared
Signature* default_signature);
^
./tensorflow_serving/session_bundle/signature.h:100:26: error: 'Signature' has not been declared
Signature* default_signature);
^
./tensorflow_serving/session_bundle/signature.h:106:32: error: 'GenericSignature' does not name a type
Status BindGenericInputs(const GenericSignature& signature,
^
./tensorflow_serving/session_bundle/signature.h:106:50: error: ISO C++ forbids declaration of 'signature' with no type [-fpermissive]
Status BindGenericInputs(const GenericSignature& signature,
^
./tensorflow_serving/session_bundle/signature.h:117:31: error: 'GenericSignature' does not name a type
Status BindGenericNames(const GenericSignature& signature,
^
./tensorflow_serving/session_bundle/signature.h:117:49: error: ISO C++ forbids declaration of 'signature' with no type [-fpermissive]
Status BindGenericNames(const GenericSignature& signature,
^
tensorflow_serving/session_bundle/session_bundle.cc:68:49: error: 'AssetFile' was not declared in this scope
const std::vector<AssetFile>& asset_files,
^
tensorflow_serving/session_bundle/session_bundle.cc:68:49: note: suggested alternative:
In file included from ./tensorflow_serving/session_bundle/manifest.pb.h:19:0,
from ./tensorflow_serving/session_bundle/session_bundle.h:29,
from tensorflow_serving/session_bundle/session_bundle.cc:16:
bazel-out/local-fastbuild/genfiles/external/org_tensorflow/tensorflow/contrib/session_bundle/manifest.pb.h:237:7: note: 'tensorflow::contrib::AssetFile'
class AssetFile : public ::google::protobuf::Message {
^
tensorflow_serving/session_bundle/session_bundle.cc:68:58: error: template argument 1 is invalid
const std::vector<AssetFile>& asset_files,
^
tensorflow_serving/session_bundle/session_bundle.cc:68:58: error: template argument 2 is invalid
tensorflow_serving/session_bundle/session_bundle.cc: In function 'void tensorflow::serving::{anonymous}::AddAssetsTensorsToInputs(tensorflow::StringPiece, const int&, std::vector<std::pair<std::basic_string<char>, tensorflow::Tensor> >*)':
tensorflow_serving/session_bundle/session_bundle.cc:70:20: error: request for member 'empty' in 'asset_files', which is of non-class type 'const int'
if (!asset_files.empty()) {
^
tensorflow_serving/session_bundle/session_bundle.cc:71:24: error: no matching function for call to 'begin(const int&)'
for (auto& asset : asset_files) {
^
tensorflow_serving/session_bundle/session_bundle.cc:71:24: note: candidates are:
In file included from /usr/include/c++/4.8/string:51:0,
from /usr/include/c++/4.8/stdexcept:39,
from /usr/include/c++/4.8/array:38,
from /usr/include/c++/4.8/tuple:39,
from /usr/include/c++/4.8/functional:55,
from /usr/include/c++/4.8/memory:79,
from ./tensorflow_serving/session_bundle/session_bundle.h:21,
from tensorflow_serving/session_bundle/session_bundle.cc:16:
/usr/include/c++/4.8/bits/range_access.h:87:5: note: template<class _Tp, long unsigned int _Nm> _Tp* std::begin(_Tp (&)[_Nm])
begin(_Tp (&__arr)[_Nm])
^
/usr/include/c++/4.8/bits/range_access.h:87:5: note: template argument deduction/substitution failed:
tensorflow_serving/session_bundle/session_bundle.cc:71:24: note: mismatched types '_Tp [_Nm]' and 'const int'
for (auto& asset : asset_files) {
^
In file included from /usr/include/c++/4.8/string:51:0,
from /usr/include/c++/4.8/stdexcept:39,
from /usr/include/c++/4.8/array:38,
from /usr/include/c++/4.8/tuple:39,
from /usr/include/c++/4.8/functional:55,
from /usr/include/c++/4.8/memory:79,
from ./tensorflow_serving/session_bundle/session_bundle.h:21,
from tensorflow_serving/session_bundle/session_bundle.cc:16:
/usr/include/c++/4.8/bits/range_access.h:58:5: note: template<class _Container> decltype (__cont.begin()) std::begin(const _Container&)
begin(const _Container& __cont) -> decltype(__cont.begin())
^
/usr/include/c++/4.8/bits/range_access.h:58:5: note: template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/range_access.h: In substitution of 'template<class _Container> decltype (__cont.begin()) std::begin(const _Container&) [with _Container = int]':
tensorflow_serving/session_bundle/session_bundle.cc:71:24: required from here
/usr/include/c++/4.8/bits/range_access.h:58:5: error: request for member 'begin' in '__cont', which is of non-class type 'const int'
/usr/include/c++/4.8/bits/range_access.h:48:5: note: template<class _Container> decltype (__cont.begin()) std::begin(_Container&)
begin(_Container& __cont) -> decltype(__cont.begin())
^
/usr/include/c++/4.8/bits/range_access.h:48:5: note: template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/range_access.h: In substitution of 'template<class _Container> decltype (__cont.begin()) std::begin(_Container&) [with _Container = const int]':
tensorflow_serving/session_bundle/session_bundle.cc:71:24: required from here
/usr/include/c++/4.8/bits/range_access.h:48:5: error: request for member 'begin' in '__cont', which is of non-class type 'const int'
In file included from /usr/include/c++/4.8/utility:74:0,
from /usr/include/c++/4.8/tuple:38,
from /usr/include/c++/4.8/functional:55,
from /usr/include/c++/4.8/memory:79,
from ./tensorflow_serving/session_bundle/session_bundle.h:21,
from tensorflow_serving/session_bundle/session_bundle.cc:16:
/usr/include/c++/4.8/initializer_list:89:5: note: template<class _Tp> constexpr const _Tp* std::begin(std::initializer_list<_Tp>)
begin(initializer_list<_Tp> __ils) noexcept
^
/usr/include/c++/4.8/initializer_list:89:5: note: template argument deduction/substitution failed:
tensorflow_serving/session_bundle/session_bundle.cc:71:24: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
for (auto& asset : asset_files) {
^
tensorflow_serving/session_bundle/session_bundle.cc:71:24: error: no matching function for call to 'end(const int&)'
tensorflow_serving/session_bundle/session_bundle.cc:71:24: note: candidates are:
In file included from /usr/include/c++/4.8/string:51:0,
from /usr/include/c++/4.8/stdexcept:39,
from /usr/include/c++/4.8/array:38,
from /usr/include/c++/4.8/tuple:39,
from /usr/include/c++/4.8/functional:55,
from /usr/include/c++/4.8/memory:79,
from ./tensorflow_serving/session_bundle/session_bundle.h:21,
from tensorflow_serving/session_bundle/session_bundle.cc:16:
/usr/include/c++/4.8/bits/range_access.h:97:5: note: template<class _Tp, long unsigned int _Nm> _Tp* std::end(_Tp (&)[_Nm])
end(_Tp (&__arr)[_Nm])
^
/usr/include/c++/4.8/bits/range_access.h:97:5: note: template argument deduction/substitution failed:
tensorflow_serving/session_bundle/session_bundle.cc:71:24: note: mismatched types '_Tp [_Nm]' and 'const int'
for (auto& asset : asset_files) {
^
In file included from /usr/include/c++/4.8/string:51:0,
from /usr/include/c++/4.8/stdexcept:39,
from /usr/include/c++/4.8/array:38,
from /usr/include/c++/4.8/tuple:39,
from /usr/include/c++/4.8/functional:55,
from /usr/include/c++/4.8/memory:79,
from ./tensorflow_serving/session_bundle/session_bundle.h:21,
from tensorflow_serving/session_bundle/session_bundle.cc:16:
/usr/include/c++/4.8/bits/range_access.h:78:5: note: template<class _Container> decltype (__cont.end()) std::end(const _Container&)
end(const _Container& __cont) -> decltype(__cont.end())
^
/usr/include/c++/4.8/bits/range_access.h:78:5: note: template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/range_access.h: In substitution of 'template<class _Container> decltype (__cont.end()) std::end(const _Container&) [with _Container = int]':
tensorflow_serving/session_bundle/session_bundle.cc:71:24: required from here
/usr/include/c++/4.8/bits/range_access.h:78:5: error: request for member 'end' in '__cont', which is of non-class type 'const int'
/usr/include/c++/4.8/bits/range_access.h:68:5: note: template<class _Container> decltype (__cont.end()) std::end(_Container&)
end(_Container& __cont) -> decltype(__cont.end())
^
/usr/include/c++/4.8/bits/range_access.h:68:5: note: template argument deduction/substitution failed:
/usr/include/c++/4.8/bits/range_access.h: In substitution of 'template<class _Container> decltype (__cont.end()) std::end(_Container&) [with _Container = const int]':
tensorflow_serving/session_bundle/session_bundle.cc:71:24: required from here
/usr/include/c++/4.8/bits/range_access.h:68:5: error: request for member 'end' in '__cont', which is of non-class type 'const int'
In file included from /usr/include/c++/4.8/utility:74:0,
from /usr/include/c++/4.8/tuple:38,
from /usr/include/c++/4.8/functional:55,
from /usr/include/c++/4.8/memory:79,
from ./tensorflow_serving/session_bundle/session_bundle.h:21,
from tensorflow_serving/session_bundle/session_bundle.cc:16:
/usr/include/c++/4.8/initializer_list:99:5: note: template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)
end(initializer_list<_Tp> __ils) noexcept
^
/usr/include/c++/4.8/initializer_list:99:5: note: template argument deduction/substitution failed:
tensorflow_serving/session_bundle/session_bundle.cc:71:24: note: mismatched types 'std::initializer_list<_Tp>' and 'int'
for (auto& asset : asset_files) {
^
tensorflow_serving/session_bundle/session_bundle.cc:76:69: error: no matching function for call to 'std::vector<std::pair<std::basic_string<char>, tensorflow::Tensor> >::push_back(<brace-enclosed initializer list>)'
{asset.tensor_binding().tensor_name(), assets_file_tensor});
^
tensorflow_serving/session_bundle/session_bundle.cc:76:69: note: candidates are:
In file included from /usr/include/c++/4.8/vector:64:0,
from external/protobuf/src/google/protobuf/unknown_field_set.h:43,
from external/protobuf/src/google/protobuf/metadata.h:43,
from bazel-out/local-fastbuild/genfiles/external/org_tensorflow/tensorflow/core/lib/core/error_codes.pb.h:25,
from external/org_tensorflow/tensorflow/core/lib/core/status.h:22,
from ./tensorflow_serving/session_bundle/session_bundle.h:23,
from tensorflow_serving/session_bundle/session_bundle.cc:16:
/usr/include/c++/4.8/bits/stl_vector.h:901:7: note: void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = std::pair<std::basic_string<char>, tensorflow::Tensor>; _Alloc = std::allocator<std::pair<std::basic_string<char>, tensorflow::Tensor> >; std::vector<_Tp, _Alloc>::value_type = std::pair<std::basic_string<char>, tensorflow::Tensor>]
push_back(const value_type& __x)
^
/usr/include/c++/4.8/bits/stl_vector.h:901:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type& {aka const std::pair<std::basic_string<char>, tensorflow::Tensor>&}'
/usr/include/c++/4.8/bits/stl_vector.h:919:7: note: void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = std::pair<std::basic_string<char>, tensorflow::Tensor>; _Alloc = std::allocator<std::pair<std::basic_string<char>, tensorflow::Tensor> >; std::vector<_Tp, _Alloc>::value_type = std::pair<std::basic_string<char>, tensorflow::Tensor>]
push_back(value_type&& __x)
^
/usr/include/c++/4.8/bits/stl_vector.h:919:7: note: no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::vector<std::pair<std::basic_string<char>, tensorflow::Tensor> >::value_type&& {aka std::pair<std::basic_string<char>, tensorflow::Tensor>&&}'
tensorflow_serving/session_bundle/session_bundle.cc: At global scope:
tensorflow_serving/session_bundle/session_bundle.cc:103:39: error: 'AssetFile' was not declared in this scope
const std::vector<AssetFile>& asset_files,
^
tensorflow_serving/session_bundle/session_bundle.cc:103:39: note: suggested alternative:
In file included from ./tensorflow_serving/session_bundle/manifest.pb.h:19:0,
from ./tensorflow_serving/session_bundle/session_bundle.h:29,
from tensorflow_serving/session_bundle/session_bundle.cc:16:
bazel-out/local-fastbuild/genfiles/external/org_tensorflow/tensorflow/contrib/session_bundle/manifest.pb.h:237:7: note: 'tensorflow::contrib::AssetFile'
class AssetFile : public ::google::protobuf::Message {
^
tensorflow_serving/session_bundle/session_bundle.cc:103:48: error: template argument 1 is invalid
const std::vector<AssetFile>& asset_files,
^
tensorflow_serving/session_bundle/session_bundle.cc:103:48: error: template argument 2 is invalid
tensorflow_serving/session_bundle/session_bundle.cc:117:36: error: 'AssetFile' was not declared in this scope
const std::vector<AssetFile>& asset_files,
^
tensorflow_serving/session_bundle/session_bundle.cc:117:36: note: suggested alternative:
In file included from ./tensorflow_serving/session_bundle/manifest.pb.h:19:0,
from ./tensorflow_serving/session_bundle/session_bundle.h:29,
from tensorflow_serving/session_bundle/session_bundle.cc:16:
bazel-out/local-fastbuild/genfiles/external/org_tensorflow/tensorflow/contrib/session_bundle/manifest.pb.h:237:7: note: 'tensorflow::contrib::AssetFile'
class AssetFile : public ::google::protobuf::Message {
^
tensorflow_serving/session_bundle/session_bundle.cc:117:45: error: template argument 1 is invalid
const std::vector<AssetFile>& asset_files,
^
tensorflow_serving/session_bundle/session_bundle.cc:117:45: error: template argument 2 is invalid
tensorflow_serving/session_bundle/session_bundle.cc: In function 'tensorflow::Status tensorflow::serving::LoadSessionBundleFromPath(const tensorflow::SessionOptions&, tensorflow::StringPiece, tensorflow::serving::SessionBundle*)':
tensorflow_serving/session_bundle/session_bundle.cc:165:15: error: 'AssetFile' was not declared in this scope
std::vector<AssetFile> asset_files;
^
tensorflow_serving/session_bundle/session_bundle.cc:165:15: note: suggested alternative:
In file included from ./tensorflow_serving/session_bundle/manifest.pb.h:19:0,
from ./tensorflow_serving/session_bundle/session_bundle.h:29,
from tensorflow_serving/session_bundle/session_bundle.cc:16:
bazel-out/local-fastbuild/genfiles/external/org_tensorflow/tensorflow/contrib/session_bundle/manifest.pb.h:237:7: note: 'tensorflow::contrib::AssetFile'
class AssetFile : public ::google::protobuf::Message {
^
tensorflow_serving/session_bundle/session_bundle.cc:165:24: error: template argument 1 is invalid
std::vector<AssetFile> asset_files;
^
tensorflow_serving/session_bundle/session_bundle.cc:165:24: error: template argument 2 is invalid
tensorflow_serving/session_bundle/session_bundle.cc:165:37: error: invalid type in declaration before ';' token
std::vector<AssetFile> asset_files;
^
tensorflow_serving/session_bundle/session_bundle.cc:170:17: error: expected ';' before 'asset_file'
AssetFile asset_file;
^
tensorflow_serving/session_bundle/session_bundle.cc:171:25: error: the value of 'AssetFile' is not usable in a constant expression
if (!any_asset.Is<AssetFile>()) {
^
tensorflow_serving/session_bundle/session_bundle.cc:165:15: note: 'AssetFile' was not declared 'constexpr'
std::vector<AssetFile> asset_files;
^
tensorflow_serving/session_bundle/session_bundle.cc:171:36: error: no matching function for call to 'google::protobuf::Any::Is() const'
if (!any_asset.Is<AssetFile>()) {
^
tensorflow_serving/session_bundle/session_bundle.cc:171:36: note: candidate is:
In file included from bazel-out/local-fastbuild/genfiles/external/org_tensorflow/tensorflow/core/protobuf/meta_graph.pb.h:32:0,
from ./tensorflow_serving/session_bundle/session_bundle.h:25,
from tensorflow_serving/session_bundle/session_bundle.cc:16:
external/protobuf/src/google/protobuf/any.pb.h:66:29: note: template<class T> bool google::protobuf::Any::Is() const
template<typename T> bool Is() const {
^
external/protobuf/src/google/protobuf/any.pb.h:66:29: note: template argument deduction/substitution failed:
tensorflow_serving/session_bundle/session_bundle.cc:174:13: error: 'asset_file' was not declared in this scope
asset_file.descriptor()->full_name(), ". Got: ",
^
tensorflow_serving/session_bundle/session_bundle.cc:178:32: error: 'asset_file' was not declared in this scope
if (!any_asset.UnpackTo(&asset_file)) {
^
tensorflow_serving/session_bundle/session_bundle.cc:182:19: error: request for member 'push_back' in 'asset_files', which is of non-class type 'int'
asset_files.push_back(asset_file);
^
tensorflow_serving/session_bundle/session_bundle.cc:182:29: error: 'asset_file' was not declared in this scope
asset_files.push_back(asset_file);
^
Target //tensorflow_serving/example:mnist_inference_2 failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 4.822s, Critical Path: 4.54s
From the page you linked: "Before getting started, please complete the prerequisites."
The type Signatures is defined in a header generated by following said prereqs process, so you've either not followed those steps or not followed them correctly – there's no way to tell which just from the compiler errors.
What is the rationale for selectively excising template member functions from class interfaces when the arguments do not satisfy various criteria, tested for with enable_if etc? If the member function templates were left in, attempting to use them would fail, and it seems to me, with a more useful compiler error than 'substitution failure' in the more complex case?
If compilation fails either way, what is the argument in favor of these extremely strict SFINAE-based template member function requirements?
Compiler errors 2-5 deep in template code have been found to be nearly impenetrable. You get a spew of template noise.
SFINAE substitution failures usually list a template and say it doesn't work because some argument cannot be deduced, often with the trait that failed displayed. Not perfect, but better than template spew.
What more, such templates can block other ones which are valid.
In addition, you can test if a given method exists and is valid at compile time if you use SFINAE-like techniques; you cannot if the body fails to compile.
Which error message do you find easier to understand. This one with SFINAE?
template <class C, class = decltype(begin(std::declval<C&>())[0])>
void sort_sfinae(C& c) {
std::sort(c.begin(), c.end());
}
main.cpp: In function 'int main()':
main.cpp:11:18: error: no matching function for call to 'sort_sfinae(std::__cxx11::list<int>&)'
sort_sfinae(l);
^
main.cpp:5:6: note: candidate: template<class C, class> void sort_sfinae(C&)
void sort_sfinae(C& c) {
^
main.cpp:5:6: note: template argument deduction/substitution failed:
main.cpp:4:62: error: no match for 'operator[]' (operand types are 'std::__cxx11::list<int>::iterator {aka std::_List_iterator<int>}' and 'int')
template <class C, class = decltype(begin(std::declval<C&>())[0])>
^
Or this one without?
template <class C>
void sort_no_sfinae(C& c) {
std::sort(c.begin(), c.end());
}
In file included from /usr/local/include/c++/5.3.0/algorithm:62:0,
from main.cpp:2:
/usr/local/include/c++/5.3.0/bits/stl_algo.h: In instantiation of 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_List_iterator<int>; _Compare = __gnu_cxx::__ops::_Iter_less_iter]':
/usr/local/include/c++/5.3.0/bits/stl_algo.h:4698:18: required from 'void std::sort(_RAIter, _RAIter) [with _RAIter = std::_List_iterator<int>]'
main.cpp:6:14: required from 'void sort_no_sfinae(C&) [with C = std::__cxx11::list<int>]'
main.cpp:11:21: required from here
/usr/local/include/c++/5.3.0/bits/stl_algo.h:1964:22: error: no match for 'operator-' (operand types are 'std::_List_iterator<int>' and 'std::_List_iterator<int>')
std::__lg(__last - __first) * 2,
^
In file included from /usr/local/include/c++/5.3.0/bits/stl_algobase.h:67:0,
from /usr/local/include/c++/5.3.0/list:60,
from main.cpp:1:
/usr/local/include/c++/5.3.0/bits/stl_iterator.h:328:5: note: candidate: template<class _Iterator> typename std::reverse_iterator<_Iterator>::difference_type std::operator-(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)
operator-(const reverse_iterator<_Iterator>& __x,
^
/usr/local/include/c++/5.3.0/bits/stl_iterator.h:328:5: note: template argument deduction/substitution failed:
In file included from /usr/local/include/c++/5.3.0/algorithm:62:0,
from main.cpp:2:
/usr/local/include/c++/5.3.0/bits/stl_algo.h:1964:22: note: 'std::_List_iterator<int>' is not derived from 'const std::reverse_iterator<_Iterator>'
std::__lg(__last - __first) * 2,
^
In file included from /usr/local/include/c++/5.3.0/bits/stl_algobase.h:67:0,
from /usr/local/include/c++/5.3.0/list:60,
from main.cpp:1:
/usr/local/include/c++/5.3.0/bits/stl_iterator.h:380:5: note: candidate: template<class _IteratorL, class _IteratorR> decltype ((__y.base() - __x.base())) std::operator-(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)
operator-(const reverse_iterator<_IteratorL>& __x,
^
/usr/local/include/c++/5.3.0/bits/stl_iterator.h:380:5: note: template argument deduction/substitution failed:
In file included from /usr/local/include/c++/5.3.0/algorithm:62:0,
from main.cpp:2:
/usr/local/include/c++/5.3.0/bits/stl_algo.h:1964:22: note: 'std::_List_iterator<int>' is not derived from 'const std::reverse_iterator<_Iterator>'
std::__lg(__last - __first) * 2,
^
In file included from /usr/local/include/c++/5.3.0/bits/stl_algobase.h:67:0,
from /usr/local/include/c++/5.3.0/list:60,
from main.cpp:1:
/usr/local/include/c++/5.3.0/bits/stl_iterator.h:1138:5: note: candidate: template<class _IteratorL, class _IteratorR> decltype ((__x.base() - __y.base())) std::operator-(const std::move_iterator<_Iterator>&, const std::move_iterator<_IteratorR>&)
operator-(const move_iterator<_IteratorL>& __x,
^
/usr/local/include/c++/5.3.0/bits/stl_iterator.h:1138:5: note: template argument deduction/substitution failed:
In file included from /usr/local/include/c++/5.3.0/algorithm:62:0,
from main.cpp:2:
/usr/local/include/c++/5.3.0/bits/stl_algo.h:1964:22: note: 'std::_List_iterator<int>' is not derived from 'const std::move_iterator<_Iterator>'
std::__lg(__last - __first) * 2,
^
In file included from /usr/local/include/c++/5.3.0/bits/stl_algobase.h:67:0,
from /usr/local/include/c++/5.3.0/list:60,
from main.cpp:1:
/usr/local/include/c++/5.3.0/bits/stl_iterator.h:1145:5: note: candidate: template<class _Iterator> decltype ((__x.base() - __y.base())) std::operator-(const std::move_iterator<_Iterator>&, const std::move_iterator<_Iterator>&)
operator-(const move_iterator<_Iterator>& __x,
^
/usr/local/include/c++/5.3.0/bits/stl_iterator.h:1145:5: note: template argument deduction/substitution failed:
In file included from /usr/local/include/c++/5.3.0/algorithm:62:0,
from main.cpp:2:
/usr/local/include/c++/5.3.0/bits/stl_algo.h:1964:22: note: 'std::_List_iterator<int>' is not derived from 'const std::move_iterator<_Iterator>'
std::__lg(__last - __first) * 2,
^
In file included from /usr/local/include/c++/5.3.0/vector:65:0,
from /usr/local/include/c++/5.3.0/bits/random.h:34,
from /usr/local/include/c++/5.3.0/random:49,
from /usr/local/include/c++/5.3.0/bits/stl_algo.h:66,
from /usr/local/include/c++/5.3.0/algorithm:62,
from main.cpp:2:
/usr/local/include/c++/5.3.0/bits/stl_bvector.h:208:3: note: candidate: std::ptrdiff_t std::operator-(const std::_Bit_iterator_base&, const std::_Bit_iterator_base&)
operator-(const _Bit_iterator_base& __x, const _Bit_iterator_base& __y)
^
/usr/local/include/c++/5.3.0/bits/stl_bvector.h:208:3: note: no known conversion for argument 1 from 'std::_List_iterator<int>' to 'const std::_Bit_iterator_base&'
I'm trying to make a method which constructs a tuple from provided parameters, and 'fills' it recursively. Unfortunately, it yields compilation errors... This is the code:
template<typename Head, typename... Tail>
std::vector<IntersectionComponents<Head, Tail...>> intersection() {
std::vector<IntersectionComponents<Head, Tail...>> results;
auto& headComponents = *getAllComponents<Head>();
for (auto& headComponent : headComponents) {
IntersectionComponents<Head, Tail...> currentEntityRequiredComponents;
if (allComponentsExist<IntersectionComponents<Head, Tail...>, Tail...>(headComponent.entityID, currentEntityRequiredComponents)) {
currentEntityRequiredComponents.set(headComponent);
results.push_back(std::move(currentEntityRequiredComponents));
}
}
return results;
}
template<typename IntersectComponents, typename Head, typename... Tail>
bool allComponentsExist(EntityID entityID, IntersectComponents& components) {
auto currentComponent = getComponent<Head>(entityID);
if (!currentComponent) {
return false;
}
if (allComponentsExist<IntersectComponents, Tail...>(entityID, components)) {
components.set(currentComponent);
return true;
}
return false;
}
It's not self contained, but I've tested IntersectionComponents class and it works. Code breaks on allComponentsExist call. It's template parameters probably need to be specified some other way...
This is definition of IntersectionComponents class, in case it would be helpful:
template<typename... ComponentTypes>
class IntersectionComponents {
public:
template<typename ComponentType>
ComponentType& get() {
return *getByType<ComponentType*>(components);
}
private:
std::tuple<ComponentTypes* ...> components;
template<typename ComponentType>
void set(ComponentType& component) {
getByType<ComponentType*>(components) = &component;
}
friend class ComponentsManager;
};
getByType function returns reference to object in a tuple with the specified type(in template parameter).
Here's the error list from compiler(completely incomprehensible for me ;/):
In file included from /usr/include/c++/5.2.0/functional:55:0,
from /usr/include/c++/5.2.0/memory:79,
from /mnt/data/dev/Active/ECS/src/3party/catch.hpp:426,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:1:
/usr/include/c++/5.2.0/tuple: In instantiation of ‘struct std::tuple_element<1ul, std::tuple<BarComponent*> >’:
/usr/include/c++/5.2.0/tuple:755:12: required from ‘struct std::tuple_element<2ul, std::tuple<FooComponent*, BarComponent*> >’
/usr/include/c++/5.2.0/tuple:769:69: required by substitution of ‘template<long unsigned int __i, class _Tp> using __tuple_element_t = typename std::tuple_element::type [with long unsigned int __i = 2ul; _Tp = std::tuple<FooComponent*, BarComponent*>]’
/usr/include/c++/5.2.0/tuple:844:5: required by substitution of ‘template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(std::tuple<_Elements ...>&&) [with long unsigned int __i = 2ul; _Elements = {FooComponent*, BarComponent*}]’
/mnt/data/dev/Active/ECS/src/utils/getTupleElementByID.h:31:103: required from ‘T& getByType(std::tuple<_Elements ...>&) [with T = BarComponent**; TupleElems = {FooComponent*, BarComponent*}]’
/mnt/data/dev/Active/ECS/include/../src/core/componentsManager.h:27:34: required from ‘void IntersectionComponents<ComponentTypes>::set(ComponentType&) [with ComponentType = BarComponent*; ComponentTypes = {FooComponent, BarComponent}]’
/mnt/data/dev/Active/ECS/include/../src/core/componentsManager.h:148:13: required from ‘bool ComponentsManager::allComponentsExist(EntityID, IntersectComponents&) [with IntersectComponents = IntersectionComponents<FooComponent, BarComponent>; Head = BarComponent; Tail = {}; EntityID = unsigned int]’
/mnt/data/dev/Active/ECS/include/../src/core/componentsManager.h:118:83: required from ‘std::vector<IntersectionComponents<Head, Tail ...> > ComponentsManager::intersection() [with Head = FooComponent; Tail = {BarComponent}]’
/mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:75:64: required from here
/usr/include/c++/5.2.0/tuple:755:12: error: invalid use of incomplete type ‘struct std::tuple_element<0ul, std::tuple<> >’
struct tuple_element<__i, tuple<_Head, _Tail...> >
^
In file included from /usr/include/c++/5.2.0/algorithm:60:0,
from /mnt/data/dev/Active/ECS/src/3party/catch.hpp:67,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:1:
/usr/include/c++/5.2.0/utility:85:11: note: declaration of ‘struct std::tuple_element<0ul, std::tuple<> >’
class tuple_element;
^
In file included from /mnt/data/dev/Active/ECS/include/../src/core/componentsManager.h:4:0,
from /mnt/data/dev/Active/ECS/include/../src/core/engine.h:4,
from /mnt/data/dev/Active/ECS/./include/ecs/ecs.h:3,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:2:
/mnt/data/dev/Active/ECS/src/utils/getTupleElementByID.h: In instantiation of ‘T& getByType(std::tuple<_Elements ...>&) [with T = BarComponent**; TupleElems = {FooComponent*, BarComponent*}]’:
/mnt/data/dev/Active/ECS/include/../src/core/componentsManager.h:27:34: required from ‘void IntersectionComponents<ComponentTypes>::set(ComponentType&) [with ComponentType = BarComponent*; ComponentTypes = {FooComponent, BarComponent}]’
/mnt/data/dev/Active/ECS/include/../src/core/componentsManager.h:148:13: required from ‘bool ComponentsManager::allComponentsExist(EntityID, IntersectComponents&) [with IntersectComponents = IntersectionComponents<FooComponent, BarComponent>; Head = BarComponent; Tail = {}; EntityID = unsigned int]’
/mnt/data/dev/Active/ECS/include/../src/core/componentsManager.h:118:83: required from ‘std::vector<IntersectionComponents<Head, Tail ...> > ComponentsManager::intersection() [with Head = FooComponent; Tail = {BarComponent}]’
/mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:75:64: required from here
/mnt/data/dev/Active/ECS/src/utils/getTupleElementByID.h:31:103: error: no matching function for call to ‘get(std::tuple<FooComponent*, BarComponent*>&)’
return std::get<detail::get_number_of_element_from_tuple_by_type_impl<T, 0, TupleElems...>::value>(t);
^
In file included from /usr/include/c++/5.2.0/algorithm:60:0,
from /mnt/data/dev/Active/ECS/src/3party/catch.hpp:67,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:1:
/usr/include/c++/5.2.0/utility:147:5: note: candidate: template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(std::pair<_Tp1, _Tp2>&)
get(std::pair<_Tp1, _Tp2>& __in) noexcept
^
/usr/include/c++/5.2.0/utility:147:5: note: template argument deduction/substitution failed:
In file included from /mnt/data/dev/Active/ECS/include/../src/core/componentsManager.h:4:0,
from /mnt/data/dev/Active/ECS/include/../src/core/engine.h:4,
from /mnt/data/dev/Active/ECS/./include/ecs/ecs.h:3,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:2:
/mnt/data/dev/Active/ECS/src/utils/getTupleElementByID.h:31:103: note: ‘std::tuple<FooComponent*, BarComponent*>’ is not derived from ‘std::pair<_Tp1, _Tp2>’
return std::get<detail::get_number_of_element_from_tuple_by_type_impl<T, 0, TupleElems...>::value>(t);
^
In file included from /usr/include/c++/5.2.0/algorithm:60:0,
from /mnt/data/dev/Active/ECS/src/3party/catch.hpp:67,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:1:
/usr/include/c++/5.2.0/utility:152:5: note: candidate: template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&& std::get(std::pair<_Tp1, _Tp2>&&)
get(std::pair<_Tp1, _Tp2>&& __in) noexcept
^
/usr/include/c++/5.2.0/utility:152:5: note: template argument deduction/substitution failed:
In file included from /mnt/data/dev/Active/ECS/include/../src/core/componentsManager.h:4:0,
from /mnt/data/dev/Active/ECS/include/../src/core/engine.h:4,
from /mnt/data/dev/Active/ECS/./include/ecs/ecs.h:3,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:2:
/mnt/data/dev/Active/ECS/src/utils/getTupleElementByID.h:31:103: note: ‘std::tuple<FooComponent*, BarComponent*>’ is not derived from ‘std::pair<_Tp1, _Tp2>’
return std::get<detail::get_number_of_element_from_tuple_by_type_impl<T, 0, TupleElems...>::value>(t);
^
In file included from /usr/include/c++/5.2.0/algorithm:60:0,
from /mnt/data/dev/Active/ECS/src/3party/catch.hpp:67,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:1:
/usr/include/c++/5.2.0/utility:157:5: note: candidate: template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr const typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(const std::pair<_Tp1, _Tp2>&)
get(const std::pair<_Tp1, _Tp2>& __in) noexcept
^
/usr/include/c++/5.2.0/utility:157:5: note: template argument deduction/substitution failed:
In file included from /mnt/data/dev/Active/ECS/include/../src/core/componentsManager.h:4:0,
from /mnt/data/dev/Active/ECS/include/../src/core/engine.h:4,
from /mnt/data/dev/Active/ECS/./include/ecs/ecs.h:3,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:2:
/mnt/data/dev/Active/ECS/src/utils/getTupleElementByID.h:31:103: note: ‘std::tuple<FooComponent*, BarComponent*>’ is not derived from ‘const std::pair<_Tp1, _Tp2>’
return std::get<detail::get_number_of_element_from_tuple_by_type_impl<T, 0, TupleElems...>::value>(t);
^
In file included from /usr/include/c++/5.2.0/algorithm:60:0,
from /mnt/data/dev/Active/ECS/src/3party/catch.hpp:67,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:1:
/usr/include/c++/5.2.0/utility:166:5: note: candidate: template<class _Tp, class _Up> constexpr _Tp& std::get(std::pair<_T1, _T2>&)
get(pair<_Tp, _Up>& __p) noexcept
^
/usr/include/c++/5.2.0/utility:166:5: note: template argument deduction/substitution failed:
/usr/include/c++/5.2.0/utility:171:5: note: candidate: template<class _Tp, class _Up> constexpr const _Tp& std::get(const std::pair<_T1, _T2>&)
get(const pair<_Tp, _Up>& __p) noexcept
^
/usr/include/c++/5.2.0/utility:171:5: note: template argument deduction/substitution failed:
/usr/include/c++/5.2.0/utility:176:5: note: candidate: template<class _Tp, class _Up> constexpr _Tp&& std::get(std::pair<_T1, _T2>&&)
get(pair<_Tp, _Up>&& __p) noexcept
^
/usr/include/c++/5.2.0/utility:176:5: note: template argument deduction/substitution failed:
/usr/include/c++/5.2.0/utility:181:5: note: candidate: template<class _Tp, class _Up> constexpr _Tp& std::get(std::pair<_Up, _Tp>&)
get(pair<_Up, _Tp>& __p) noexcept
^
/usr/include/c++/5.2.0/utility:181:5: note: template argument deduction/substitution failed:
/usr/include/c++/5.2.0/utility:186:5: note: candidate: template<class _Tp, class _Up> constexpr const _Tp& std::get(const std::pair<_Up, _Tp>&)
get(const pair<_Up, _Tp>& __p) noexcept
^
/usr/include/c++/5.2.0/utility:186:5: note: template argument deduction/substitution failed:
/usr/include/c++/5.2.0/utility:191:5: note: candidate: template<class _Tp, class _Up> constexpr _Tp&& std::get(std::pair<_Up, _Tp>&&)
get(pair<_Up, _Tp>&& __p) noexcept
^
/usr/include/c++/5.2.0/utility:191:5: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/5.2.0/tuple:39:0,
from /usr/include/c++/5.2.0/functional:55,
from /usr/include/c++/5.2.0/memory:79,
from /mnt/data/dev/Active/ECS/src/3party/catch.hpp:426,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:1:
/usr/include/c++/5.2.0/array:280:5: note: candidate: template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp& std::get(std::array<_Tp, _Nm>&)
get(array<_Tp, _Nm>& __arr) noexcept
^
/usr/include/c++/5.2.0/array:280:5: note: template argument deduction/substitution failed:
In file included from /mnt/data/dev/Active/ECS/include/../src/core/componentsManager.h:4:0,
from /mnt/data/dev/Active/ECS/include/../src/core/engine.h:4,
from /mnt/data/dev/Active/ECS/./include/ecs/ecs.h:3,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:2:
/mnt/data/dev/Active/ECS/src/utils/getTupleElementByID.h:31:103: note: ‘std::tuple<FooComponent*, BarComponent*>’ is not derived from ‘std::array<_Tp, _Nm>’
return std::get<detail::get_number_of_element_from_tuple_by_type_impl<T, 0, TupleElems...>::value>(t);
^
In file included from /usr/include/c++/5.2.0/tuple:39:0,
from /usr/include/c++/5.2.0/functional:55,
from /usr/include/c++/5.2.0/memory:79,
from /mnt/data/dev/Active/ECS/src/3party/catch.hpp:426,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:1:
/usr/include/c++/5.2.0/array:289:5: note: candidate: template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp&& std::get(std::array<_Tp, _Nm>&&)
get(array<_Tp, _Nm>&& __arr) noexcept
^
/usr/include/c++/5.2.0/array:289:5: note: template argument deduction/substitution failed:
In file included from /mnt/data/dev/Active/ECS/include/../src/core/componentsManager.h:4:0,
from /mnt/data/dev/Active/ECS/include/../src/core/engine.h:4,
from /mnt/data/dev/Active/ECS/./include/ecs/ecs.h:3,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:2:
/mnt/data/dev/Active/ECS/src/utils/getTupleElementByID.h:31:103: note: ‘std::tuple<FooComponent*, BarComponent*>’ is not derived from ‘std::array<_Tp, _Nm>’
return std::get<detail::get_number_of_element_from_tuple_by_type_impl<T, 0, TupleElems...>::value>(t);
^
In file included from /usr/include/c++/5.2.0/tuple:39:0,
from /usr/include/c++/5.2.0/functional:55,
from /usr/include/c++/5.2.0/memory:79,
from /mnt/data/dev/Active/ECS/src/3party/catch.hpp:426,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:1:
/usr/include/c++/5.2.0/array:297:5: note: candidate: template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr const _Tp& std::get(const std::array<_Tp, _Nm>&)
get(const array<_Tp, _Nm>& __arr) noexcept
^
/usr/include/c++/5.2.0/array:297:5: note: template argument deduction/substitution failed:
In file included from /mnt/data/dev/Active/ECS/include/../src/core/componentsManager.h:4:0,
from /mnt/data/dev/Active/ECS/include/../src/core/engine.h:4,
from /mnt/data/dev/Active/ECS/./include/ecs/ecs.h:3,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:2:
/mnt/data/dev/Active/ECS/src/utils/getTupleElementByID.h:31:103: note: ‘std::tuple<FooComponent*, BarComponent*>’ is not derived from ‘const std::array<_Tp, _Nm>’
return std::get<detail::get_number_of_element_from_tuple_by_type_impl<T, 0, TupleElems...>::value>(t);
^
In file included from /usr/include/c++/5.2.0/functional:55:0,
from /usr/include/c++/5.2.0/memory:79,
from /mnt/data/dev/Active/ECS/src/3party/catch.hpp:426,
from /mnt/data/dev/Active/ECS/tests/core/componentsManagerTests.cpp:1:
/usr/include/c++/5.2.0/tuple:832:5: note: candidate: template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >& std::get(std::tuple<_Elements ...>&)
get(tuple<_Elements...>& __t) noexcept
^
/usr/include/c++/5.2.0/tuple:832:5: note: template argument deduction/substitution failed:
/usr/include/c++/5.2.0/tuple:838:5: note: candidate: template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >& std::get(const std::tuple<_Elements ...>&)
get(const tuple<_Elements...>& __t) noexcept
^
/usr/include/c++/5.2.0/tuple:838:5: note: template argument deduction/substitution failed:
/usr/include/c++/5.2.0/tuple:844:5: note: candidate: template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(std::tuple<_Elements ...>&&)
get(tuple<_Elements...>&& __t) noexcept
^
/usr/include/c++/5.2.0/tuple:844:5: note: substitution of deduced template arguments resulted in errors seen above
/usr/include/c++/5.2.0/tuple:867:5: note: candidate: template<class _Tp, class ... _Types> constexpr _Tp& std::get(std::tuple<_Elements ...>&)
get(tuple<_Types...>& __t) noexcept
^
/usr/include/c++/5.2.0/tuple:867:5: note: template argument deduction/substitution failed:
/usr/include/c++/5.2.0/tuple:873:5: note: candidate: template<class _Tp, class ... _Types> constexpr _Tp&& std::get(std::tuple<_Elements ...>&&)
get(tuple<_Types...>&& __t) noexcept
^
/usr/include/c++/5.2.0/tuple:873:5: note: template argument deduction/substitution failed:
/usr/include/c++/5.2.0/tuple:879:5: note: candidate: template<class _Tp, class ... _Types> constexpr const _Tp& std::get(const std::tuple<_Elements ...>&)
get(const tuple<_Types...>& __t) noexcept
^
/usr/include/c++/5.2.0/tuple:879:5: note: template argument deduction/substitution failed:
CMakeFiles/tests.dir/build.make:77: polecenia dla obiektu 'CMakeFiles/tests.dir/tests/core/componentsManagerTests.cpp.o' nie powiodły się
Solved it. Well, it took 3 minutes or so after I've got 'genius' idea to just look at all error locations reported instead of trying to comprehend actual errors. And I've searched for error in the wrong place, due to IDE which underlined following line in red:
allComponentsExist<IntersectionComponents<Head, Tail...>, Tail...>(headComponent.entityID, currentEntityRequiredComponents));
Actual problem was this line:
components.set(currentComponent);
set() should get reference to object, but currentComponent was a pointer... changed it to:
components.set(*currentComponent);
And wall of errors is gone.
This line of errors made me realize this:
...componentsManager.h:27:34: required from ‘void IntersectionComponents<ComponentTypes>::set(ComponentType&) [with ComponentType = BarComponent*; ComponentTypes = {FooComponent, BarComponent}]’
Specifically "with ComponentType = BarComponent*" part :S
Anyway, sorry for bad question.