jeudi 28 décembre 2017

Do postfix operators return lvalue?

Isn't the foll code given in C++ Primer incorrect ?

ostream_iterator<int> out_iter(cout, " ");
for (auto e : vec)
    *out_iter++ = e;  // the assignment writes this element to cout
cout << endl;

The postfix operator returns the old value, not a reference then how can it be made to act as an lvalue ?

Please correct if I am wrong

mercredi 27 décembre 2017

template substitution failure with sfinae

The following code does not compiler with GCC 5.2 or later, have not tried older compiler. Amy idea on what I am doing wrong here.

#include <iostream>
#include <string>
#include <type_traits>

template <typename T>
typename std::enable_if<std::is_enum<T>::value, T>::type
operator^=(T &lhs, const T &rhs)
{
    lhs = static_cast<T>(
                 static_cast<typename std::underlying_type<T>::type>(lhs) ^
                 static_cast<typename std::underlying_type<T>::type>(rhs));
    return lhs;
}

template <typename T, typename S>
typename std::enable_if<std::is_enum<T>::value && std::is_integral<S>::value, T>::type
operator^=(T &lhs, const S &rhs)
{
    lhs = static_cast<T>(
                 static_cast<typename std::underlying_type<T>::type>(lhs) ^
                 static_cast<typename std::underlying_type<T>::type>(rhs));
    return lhs;
}

enum Enum_t{
    Red,
    Blue,
    Green,
    Black
} ;
#define somedef 2
int main(){
    Enum_t b = Red;
    b ^= somedef;

    std::cout << std::to_string(b) << std::endl;
}

I get the following error:

g++ -std=gnu++11 main.cpp

main.cpp: In function ‘int main()’:
main.cpp:34:4: error: invalid conversion from ‘int’ to ‘Enum_t’ [-fpermissive]
b ^= somedef;

Iterating through process's allocated pages - C++

I've worked a bit with processes in linux, and am now starting to work with windows. It seems to be a bit different as i'm getting a hard time finding the right way to get to what I want.

My question is: I need to iterate through some process's (specific PID that I already found) allocated pages under a page size condition. 1. How do I do such iteration? 2. Once i'm iterating, where can I find the page size?

Boost won't link

I am on Ubuntu 16.04 LTS, and I have g++ working and have downloaded boost a few minutes ago.

I have a very simple cpp file that has #include <boost/thread.hpp> in it. Compiling (running g++ -c -std=c++11 simple.cpp -o simple.o) works, however, linking won't. I tried the following options:

g++ -std=c++11 -lpthread -lboost_system-lboost_thread simple.o -o simple
g++ -std=c++11 -L/usr/bin -L/usr/lib -I/usr/include -lpthread -lboost_system-lboost_thread simple.o -o simple

One thing worthy of mentioning is that /usr/include/boost exists while /usr/lib/boost does not.

I have installed boost using: sudo apt-get install libboost-all-dev

The error I get upon linking is:

simple.o: In function `__static_initialization_and_destruction_0(int, int)':
simple.cpp:(.text+0x132): undefined reference to     `boost::system::generic_category()'
simple.cpp:(.text+0x13e): undefined reference to `boost::system::generic_category()'
simple.cpp:(.text+0x14a): undefined reference to `boost::system::system_category()'
simple.o: In function `boost::thread_exception::thread_exception(int, char const*)':
simple.cpp:(.text._ZN5boost16thread_exceptionC2EiPKc[_ZN5boost16thread_exceptionC5EiPKc]+0x23): undefined reference to `boost::system::system_category()'
simple.o: In function `boost::detail::thread_data_base::thread_data_base()':
simple.cpp:(.text._ZN5boost6detail16thread_data_baseC2Ev[_ZN5boost6detail16thread_data_baseC5Ev]+0x1e): undefined reference to `vtable for boost::detail::thread_data_base'
simple.o: In function `boost::thread::start_thread()':
simple.cpp:(.text._ZN5boost6thread12start_threadEv[_ZN5boost6thread12start_threadEv]+0x24): undefined reference to `boost::thread::start_thread_noexcept()'
simple.o: In function `boost::thread::~thread()':
simple.cpp:(.text._ZN5boost6threadD2Ev[_ZN5boost6threadD5Ev]+0x14): undefined reference to `boost::thread::detach()'
simple.o: In function `boost::thread::get_id() const':
simple.cpp:(.text._ZNK5boost6thread6get_idEv[_ZNK5boost6thread6get_idEv]+0x18): undefined reference to `boost::thread::native_handle()'
simple.o: In function `boost::thread::join()':
simple.cpp:(.text._ZN5boost6thread4joinEv[_ZN5boost6thread4joinEv]+0x88): undefined reference to `boost::thread::join_noexcept()'
simple.o: In function `Task::operator()()':
simple.cpp:(.text._ZN4TaskclEv[_ZN4TaskclEv]+0x67): undefined reference to `boost::this_thread::yield()'
simple.o: In function `boost::detail::thread_data<Task>::~thread_data()':
simple.cpp:(.text._ZN5boost6detail11thread_dataI4TaskED2Ev[_ZN5boost6detail11thread_dataI4TaskED5Ev]+0x20): undefined reference to `boost::detail::thread_data_base::~thread_data_base()'
simple.o:(.rodata._ZTIN5boost6detail11thread_dataI4TaskEE[_ZTIN5boost6detail11thread_dataI4TaskEE]+0x10): undefined reference to `typeinfo for boost::detail::thread_data_base'

Detach thread with socket as class member

I have a game server implemented in Java, however, I am migrating to C++.

I am trying to implement a server to my game. I am facing a problem when I try to detach a thread in the Client class. This thread would be responsible to listen to the client socket while the client is connect. I tried different strategies, however, I would like to keep it optimized and simple as possible. I believe the problem is related to the form that I am declaring the socket.

For the answer, rather than just pointing the problem, would be nice to check one example that fits with my structure. Moreover, I am open to opinions to improve my structure and performance of the server.

In the main, after accepting a new connection I create a new Client, and move the socket to it.

using boost::asio::ip::tcp;

void server(boost::asio::io_service&, tcp::endpoint&);

int main(int argc, char* argv[]) {
    try {
        boost::asio::io_service io_service;
        tcp::endpoint end_point(tcp::v6(), 9990);
        server(io_service, end_point);
    } catch (std::exception& e) {
        std::cerr << "Exception: " << e.what() << "\n";
    }
    return 0;
}

inline void server(boost::asio::io_service& io_service, tcp::endpoint& end_point) {
    std::shared_ptr<NetworkManager> manager(new NetworkManager());
    tcp::acceptor acceptor(io_service, end_point);
    for (;;) {
        std::cout << "Waiting for new connection." << std::endl;
        acceptor.listen();
        tcp::socket sock(io_service);
        acceptor.accept(sock);
        std::cout << "New connection accepted." << std::endl;

        std::shared_ptr<Client> client = std::shared_ptr<Client>(new Client(std::move(sock), manager));
        manager->add_client(client);
    }
}

Client class

class Client {
private:
    std::string id;
    tcp::socket& sock;
    std::shared_ptr<InterfaceManager> manager;

    void session();
    void send_start();
    void update_transform(std::string);
    std::vector<unsigned char> int_to_bytes(int);
public:
    std::shared_ptr<Position> position;
    std::shared_ptr<Rotation> rotation;

    void send_to_client(std::string);

    // Constructor and deconstructor
    Client(tcp::socket, std::shared_ptr<InterfaceManager>);
    virtual ~Client();

    // Getters and Setters
    std::string get_id() const;
};

In the constructor of the Client, store the manager which will contains all clients for broacasting, define UUID, position, rotation (for the transform), and detach() the thread. I tried to join() and it works for one client (because it does not continues in the main after creating the Client object).

Client::Client(tcp::socket socket, std::shared_ptr<InterfaceManager> i_manager) :
        sock(socket) {
    // For broadcast
    this->manager = i_manager;

    // Create UUID
    boost::uuids::uuid uuid = boost::uuids::random_generator()();
    id = to_string(uuid);
    std::cout << "Client " << id << " connected." << std::endl;

    // Define position and rotation
    this->position = std::shared_ptr<Position>(new Position("0", "0", "0"));
    this->rotation = std::shared_ptr<Rotation>(new Rotation("0", "0", "0", "0"));

    // Start client thread
    std::thread(&Client::session, this).detach();
}

The thread Client::session is this coded as bellow. This is a simple receive/reply thread (just for testing).

void Client::session() {
    // Send start command
    send_start();
    try {
        for (;;) {
            char data[1024];

            boost::system::error_code error;
            sock.read_some(boost::asio::buffer(data), error);

            if (error == boost::asio::error::eof) {
                puts("Connection closed cleanly by peer");
                break;
            } else if (error) {
                puts("Some other error");
                throw boost::system::system_error(error);
            }

            std::string str(data);
            std::cout << "Data received: " << data << std::endl;

            //update_transform(str);
            //manager->broadcast(id, str);

            std::string s = "The received message is: " + str;

            char* answer = const_cast<char*>(s.c_str());
            size_t answer_length = std::strlen(answer);
            boost::asio::write(sock, boost::asio::buffer(answer, answer_length));

        }
    } catch (std::exception& e) {
        std::cerr << "Exception in thread: " << e.what() << "\n";
        sock.close();
    }
    std::cout << "Client " << id << " closed its connection." << std::endl;
    sock.close();
}

Apache thrift multi client server

I am writing simple chat in Qt + Apache Thrift but right now I need to face a problem with connecting multiple clients. On first sight everything looks good and I cannot find where the problem is.

Here is my server main.cpp:

int main(int argc, char **argv) 
{
    int port = 9090;

    ::apache::thrift::stdcxx::shared_ptr<UsersStorageHandler> handler(new UsersStorageHandler());
    ::apache::thrift::stdcxx::shared_ptr<TProcessor> processor(new UsersStorageProcessor(handler));
    ::apache::thrift::stdcxx::shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
    ::apache::thrift::stdcxx::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
    ::apache::thrift::stdcxx::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());

    TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);

    std::cout << "Users server started..." << std::endl;
    std::cout << std::endl;
    std::cout << std::endl;

    server.serve();

    return 0;
}

Here is my server handler.h:

class UsersStorageHandler : virtual public UsersStorageIf
{
public:
    UsersStorageHandler();
    int32_t subscribeUser(const std::string& username);
    void unsubscribeUser(const int32_t userID);

private:
    Users users;
};

Here is my server handler.cpp:

UsersStorageHandler::UsersStorageHandler()
{
    srand(time(NULL));
}

int32_t UsersStorageHandler::subscribeUser(const std::string &username)
{
    ++idGenerator;

    assert(username != "");

    User user;
    user.userId  = idGenerator;
    user.username = username;
    user.colorR = (rand() % 255) + 0;
    user.colorG = (rand() % 255) + 0;
    user.colorB = (rand() % 255) + 0;
    user.colorA = 0;

    users[idGenerator] = user;

    std::cout << "NEW USER CONNECTED" << std::endl;
    std::cout << "==================" << std::endl;
    std::cout << "Username:\t" << user.username << std::endl;
    std::cout << "User ID:\t" << user.userId << std::endl;
    std::cout << "User R:\t" << user.colorR << std::endl;
    std::cout << "User G:\t" << user.colorG << std::endl;
    std::cout << "User B:\t" << user.colorB << std::endl;
    std::cout << "User A:\t" << user.colorA << std::endl;
    std::cout << "==================" << std::endl;
    std::cout << "CURRENT USERS COUNT:\t" << users.size() << std::endl;
    std::cout << std::endl;
    std::cout << std::endl;

    /*
     * SEND TO CLIENT INFO ABOUT NEW USER HERE
     */

    return idGenerator;
}

void UsersStorageHandler::unsubscribeUser(const int32_t userID)
{
    auto index = users.find(userID);

    assert(index != users.end());

    users.erase(index);

    std::cout << "USER DISCONNECTED" << std::endl;
    std::cout << "=================" << std::endl;
    std::cout << "USER WITH ID " << userID << " ERASED" << std::endl;
    std::cout << "USERS COUNT:\t" << users.size() << std::endl;
    std::cout << std::endl;
    std::cout << std::endl;

    /*
     * SEND TO CLIENT INFO ABOUT NEW USER HERE
     */
}

And right here is a method for connect to the server in client app:

void MainWindow::connectToServers(const std::string &ip, const uint32_t &port, const std::string &nick)
{
    m_usersServerIP = ip;
    m_usersServerPort = port;

    try
    {
        ::apache::thrift::stdcxx::shared_ptr<TTransport> socket(new TSocket(m_usersServerIP, m_usersServerPort));
        ::apache::thrift::stdcxx::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
        ::apache::thrift::stdcxx::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));

        m_usersServerClient = std::make_shared<UsersStorageClient>(protocol);
        transport->open();

        m_clientID = m_usersServerClient.get()->subscribeUser(nick);

        QMessageBox::information(this, "Connected",
                             "You are connected "
                             "with users server");

        createAndRegisterUsersServerReactor();

        activateChatScreen();

    }
    catch (const std::exception &e)
    {
        qDebug() << e.what();
    }

    qDebug() << "ID FROM SERVER:\t" << m_clientID;
}

As far as I checked right now it is working like this: Created two instances of client app. In one instance fill nickname, ip, port and clicked connect (connectToServers method). Client connected. In another instance done the same but after clicked connected ... nothing happens. App freezes at this line:

m_clientID = m_usersServerClient.get()->subscribeUser(nick);

After closing first client, second one connects to the server.

Unique_ptr c++ usage

Sincerelly i m not so expert with c++ RAII features. I never used before. Anyway i m begining to study about it. Compiling a module i have the following error :

In file included from /usr/include/c++/6/memory:81:0,
                 from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
                 from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h: In instantiation of ‘void std::unique_ptr<_Tp [], _Dp>::reset(_Up) [with _Up = char*; <template-parameter-2-2> = void; _Tp = const char; _Dp = std::default_delete<const char []>]’:
/usr/include/c++/6/bits/unique_ptr.h:539:9:   required from ‘typename std::enable_if<std::__and_<std::__and_<std::is_array<_Up>, std::is_same<typename std::unique_ptr<_Tp [], _Dp>::_Pointer::type, _Tp*>, std::is_same<typename std::unique_ptr<_Up, _Ep>::pointer, typename std::unique_ptr<_Up, _Ep>::element_type*>, std::is_convertible<typename std::unique_ptr<_Up, _Ep>::element_type (*)[], _Tp (*)[]>, std::__or_<std::__and_<std::is_reference<_Dp>, std::is_same<_T2, _U2> >, std::__and_<std::__not_<std::is_reference<_Dp> >, std::is_convertible<_Ep, _Dp> > > >, std::is_assignable<_T2&, _U2&&> >::value, std::unique_ptr<_Tp [], _Dp>&>::type std::unique_ptr<_Tp [], _Dp>::operator=(std::unique_ptr<_Up, _Ep>&&) [with _Up = char []; _Ep = std::default_delete<char []>; _Tp = const char; _Dp = std::default_delete<const char []>; typename std::enable_if<std::__and_<std::__and_<std::is_array<_Up>, std::is_same<typename std::unique_ptr<_Tp [], _Dp>::_Pointer::type, _Tp*>, std::is_same<typename std::unique_ptr<_Up, _Ep>::pointer, typename std::unique_ptr<_Up, _Ep>::element_type*>, std::is_convertible<typename std::unique_ptr<_Up, _Ep>::element_type (*)[], _Tp (*)[]>, std::__or_<std::__and_<std::is_reference<_Dp>, std::is_same<_T2, _U2> >, std::__and_<std::__not_<std::is_reference<_Dp> >, std::is_convertible<_Ep, _Dp> > > >, std::is_assignable<_T2&, _U2&&> >::value, std::unique_ptr<_Tp [], _Dp>&>::type = std::unique_ptr<const char []>&]’
java/rocksjni/compaction_filter_factory_jnicallback.cc:33:58:   required from here
/usr/include/c++/6/bits/unique_ptr.h:614:6: error: no matching function for call to ‘swap(const char*&, char*&)’
  swap(std::get<0>(_M_t), __p);
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/bits/stl_pair.h:59:0,
                 from /usr/include/c++/6/bits/stl_algobase.h:64,
                 from /usr/include/c++/6/memory:62,
                 from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
                 from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/move.h:179:5: note: candidate: template<class _Tp> typename std::enable_if<std::__and_<std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> >::value>::type std::swap(_Tp&, _Tp&)
     swap(_Tp& __a, _Tp& __b)
     ^~~~
/usr/include/c++/6/bits/move.h:179:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
                 from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
                 from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note:   deduced conflicting types for parameter ‘_Tp’ (‘const char*’ and ‘char*’)
  swap(std::get<0>(_M_t), __p);
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/bits/stl_pair.h:59:0,
                 from /usr/include/c++/6/bits/stl_algobase.h:64,
                 from /usr/include/c++/6/memory:62,
                 from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
                 from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/move.h:202:5: note: candidate: template<class _Tp, long unsigned int _Nm> typename std::enable_if<std::__is_swappable<_Tp>::value>::type std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])
     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
     ^~~~
/usr/include/c++/6/bits/move.h:202:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
                 from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
                 from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note:   mismatched types ‘_Tp [_Nm]’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
  swap(std::get<0>(_M_t), __p);
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/6/memory:62,
                 from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
                 from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/stl_pair.h:471:5: note: candidate: template<class _T1, class _T2> void std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&)
     swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
     ^~~~
/usr/include/c++/6/bits/stl_pair.h:471:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
                 from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
                 from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note:   mismatched types ‘std::pair<_T1, _T2>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
  swap(std::get<0>(_M_t), __p);
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/string:52:0,
                 from /usr/include/c++/6/stdexcept:39,
                 from /usr/include/c++/6/array:39,
                 from /usr/include/c++/6/tuple:39,
                 from /usr/include/c++/6/functional:55,
                 from /usr/include/c++/6/memory:79,
                 from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
                 from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/basic_string.h:5287:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> void std::swap(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
     ^~~~
/usr/include/c++/6/bits/basic_string.h:5287:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
                 from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
                 from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note:   mismatched types ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
  swap(std::get<0>(_M_t), __p);
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/tuple:39:0,
                 from /usr/include/c++/6/functional:55,
                 from /usr/include/c++/6/memory:79,
                 from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
                 from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/array:275:5: note: candidate: template<class _Tp, long unsigned int _Nm> void std::swap(std::array<_Tp, _Nm>&, std::array<_Tp, _Nm>&)
     swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
     ^~~~
/usr/include/c++/6/array:275:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
                 from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
                 from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note:   mismatched types ‘std::array<_Tp, _Nm>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
  swap(std::get<0>(_M_t), __p);
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/functional:55:0,
                 from /usr/include/c++/6/memory:79,
                 from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
                 from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/tuple:1546:5: note: candidate: template<class ... _Elements> void std::swap(std::tuple<_Elements ...>&, std::tuple<_Elements ...>&)
     swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
     ^~~~
/usr/include/c++/6/tuple:1546:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
                 from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
                 from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note:   mismatched types ‘std::tuple<_Elements ...>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
  swap(std::get<0>(_M_t), __p);
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/memory:79:0,
                 from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
                 from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/functional:2238:5: note: candidate: template<class _Res, class ... _Args> void std::swap(std::function<_Res(_ArgTypes ...)>&, std::function<_Res(_ArgTypes ...)>&)
     swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y)
     ^~~~
/usr/include/c++/6/functional:2238:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
                 from ./java/./rocksjni/compaction_filter_factory_jnicallback.h:13,
                 from java/rocksjni/compaction_filter_factory_jnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note:   mismatched types ‘std::function<_Res(_ArgTypes ...)>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
  swap(std::get<0>(_M_t), __p);
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/memory:81:0,
                 from ./java/./rocksjni/comparatorjnicallback.h:13,
                 from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h: In instantiation of ‘void std::unique_ptr<_Tp [], _Dp>::reset(_Up) [with _Up = char*; <template-parameter-2-2> = void; _Tp = const char; _Dp = std::default_delete<const char []>]’:
/usr/include/c++/6/bits/unique_ptr.h:539:9:   required from ‘typename std::enable_if<std::__and_<std::__and_<std::is_array<_Up>, std::is_same<typename std::unique_ptr<_Tp [], _Dp>::_Pointer::type, _Tp*>, std::is_same<typename std::unique_ptr<_Up, _Ep>::pointer, typename std::unique_ptr<_Up, _Ep>::element_type*>, std::is_convertible<typename std::unique_ptr<_Up, _Ep>::element_type (*)[], _Tp (*)[]>, std::__or_<std::__and_<std::is_reference<_Dp>, std::is_same<_T2, _U2> >, std::__and_<std::__not_<std::is_reference<_Dp> >, std::is_convertible<_Ep, _Dp> > > >, std::is_assignable<_T2&, _U2&&> >::value, std::unique_ptr<_Tp [], _Dp>&>::type std::unique_ptr<_Tp [], _Dp>::operator=(std::unique_ptr<_Up, _Ep>&&) [with _Up = char []; _Ep = std::default_delete<char []>; _Tp = const char; _Dp = std::default_delete<const char []>; typename std::enable_if<std::__and_<std::__and_<std::is_array<_Up>, std::is_same<typename std::unique_ptr<_Tp [], _Dp>::_Pointer::type, _Tp*>, std::is_same<typename std::unique_ptr<_Up, _Ep>::pointer, typename std::unique_ptr<_Up, _Ep>::element_type*>, std::is_convertible<typename std::unique_ptr<_Up, _Ep>::element_type (*)[], _Tp (*)[]>, std::__or_<std::__and_<std::is_reference<_Dp>, std::is_same<_T2, _U2> >, std::__and_<std::__not_<std::is_reference<_Dp> >, std::is_convertible<_Ep, _Dp> > > >, std::is_assignable<_T2&, _U2&&> >::value, std::unique_ptr<_Tp [], _Dp>&>::type = std::unique_ptr<const char []>&]’
java/rocksjni/comparatorjnicallback.cc:34:21:   required from here
/usr/include/c++/6/bits/unique_ptr.h:614:6: error: no matching function for call to ‘swap(const char*&, char*&)’
  swap(std::get<0>(_M_t), __p);
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/bits/stl_pair.h:59:0,
                 from /usr/include/c++/6/bits/stl_algobase.h:64,
                 from /usr/include/c++/6/memory:62,
                 from ./java/./rocksjni/comparatorjnicallback.h:13,
                 from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/move.h:179:5: note: candidate: template<class _Tp> typename std::enable_if<std::__and_<std::is_move_constructible<_Tp>, std::is_move_assignable<_Tp> >::value>::type std::swap(_Tp&, _Tp&)
     swap(_Tp& __a, _Tp& __b)
     ^~~~
/usr/include/c++/6/bits/move.h:179:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
                 from ./java/./rocksjni/comparatorjnicallback.h:13,
                 from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note:   deduced conflicting types for parameter ‘_Tp’ (‘const char*’ and ‘char*’)
  swap(std::get<0>(_M_t), __p);
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/bits/stl_pair.h:59:0,
                 from /usr/include/c++/6/bits/stl_algobase.h:64,
                 from /usr/include/c++/6/memory:62,
                 from ./java/./rocksjni/comparatorjnicallback.h:13,
                 from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/move.h:202:5: note: candidate: template<class _Tp, long unsigned int _Nm> typename std::enable_if<std::__is_swappable<_Tp>::value>::type std::swap(_Tp (&)[_Nm], _Tp (&)[_Nm])
     swap(_Tp (&__a)[_Nm], _Tp (&__b)[_Nm])
     ^~~~
/usr/include/c++/6/bits/move.h:202:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
                 from ./java/./rocksjni/comparatorjnicallback.h:13,
                 from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note:   mismatched types ‘_Tp [_Nm]’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
  swap(std::get<0>(_M_t), __p);
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/bits/stl_algobase.h:64:0,
                 from /usr/include/c++/6/memory:62,
                 from ./java/./rocksjni/comparatorjnicallback.h:13,
                 from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/stl_pair.h:471:5: note: candidate: template<class _T1, class _T2> void std::swap(std::pair<_T1, _T2>&, std::pair<_T1, _T2>&)
     swap(pair<_T1, _T2>& __x, pair<_T1, _T2>& __y)
     ^~~~
/usr/include/c++/6/bits/stl_pair.h:471:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
                 from ./java/./rocksjni/comparatorjnicallback.h:13,
                 from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note:   mismatched types ‘std::pair<_T1, _T2>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
  swap(std::get<0>(_M_t), __p);
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/string:52:0,
                 from /usr/include/c++/6/stdexcept:39,
                 from /usr/include/c++/6/array:39,
                 from /usr/include/c++/6/tuple:39,
                 from /usr/include/c++/6/functional:55,
                 from /usr/include/c++/6/memory:79,
                 from ./java/./rocksjni/comparatorjnicallback.h:13,
                 from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/basic_string.h:5287:5: note: candidate: template<class _CharT, class _Traits, class _Alloc> void std::swap(std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&)
     swap(basic_string<_CharT, _Traits, _Alloc>& __lhs,
     ^~~~
/usr/include/c++/6/bits/basic_string.h:5287:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
                 from ./java/./rocksjni/comparatorjnicallback.h:13,
                 from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note:   mismatched types ‘std::__cxx11::basic_string<_CharT, _Traits, _Alloc>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
  swap(std::get<0>(_M_t), __p);
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/tuple:39:0,
                 from /usr/include/c++/6/functional:55,
                 from /usr/include/c++/6/memory:79,
                 from ./java/./rocksjni/comparatorjnicallback.h:13,
                 from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/array:275:5: note: candidate: template<class _Tp, long unsigned int _Nm> void std::swap(std::array<_Tp, _Nm>&, std::array<_Tp, _Nm>&)
     swap(array<_Tp, _Nm>& __one, array<_Tp, _Nm>& __two)
     ^~~~
/usr/include/c++/6/array:275:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
                 from ./java/./rocksjni/comparatorjnicallback.h:13,
                 from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note:   mismatched types ‘std::array<_Tp, _Nm>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
  swap(std::get<0>(_M_t), __p);
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/functional:55:0,
                 from /usr/include/c++/6/memory:79,
                 from ./java/./rocksjni/comparatorjnicallback.h:13,
                 from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/tuple:1546:5: note: candidate: template<class ... _Elements> void std::swap(std::tuple<_Elements ...>&, std::tuple<_Elements ...>&)
     swap(tuple<_Elements...>& __x, tuple<_Elements...>& __y)
     ^~~~
/usr/include/c++/6/tuple:1546:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
                 from ./java/./rocksjni/comparatorjnicallback.h:13,
                 from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note:   mismatched types ‘std::tuple<_Elements ...>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
  swap(std::get<0>(_M_t), __p);
  ~~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/6/memory:79:0,
                 from ./java/./rocksjni/comparatorjnicallback.h:13,
                 from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/functional:2238:5: note: candidate: template<class _Res, class ... _Args> void std::swap(std::function<_Res(_ArgTypes ...)>&, std::function<_Res(_ArgTypes ...)>&)
     swap(function<_Res(_Args...)>& __x, function<_Res(_Args...)>& __y)
     ^~~~
/usr/include/c++/6/functional:2238:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/6/memory:81:0,
                 from ./java/./rocksjni/comparatorjnicallback.h:13,
                 from java/rocksjni/comparatorjnicallback.cc:9:
/usr/include/c++/6/bits/unique_ptr.h:614:6: note:   mismatched types ‘std::function<_Res(_ArgTypes ...)>’ and ‘std::__tuple_element_t<0ul, std::tuple<const char*, std::default_delete<const char []> > > {aka const char*}’
  swap(std::get<0>(_M_t), __p);

I m not sure to understand this stack trace but it seams there is a mismatch in the unique_ptr . Maybe const char* and char*.

the class where there is the bug is :

CompactionFilterFactoryJniCallback::CompactionFilterFactoryJniCallback(
    JNIEnv* env, jobject jcompaction_filter_factory)
    : JniCallback(env, jcompaction_filter_factory) {

  // Note: The name of a CompactionFilterFactory will not change during
  // it's lifetime, so we cache it in a global var
  jmethodID jname_method_id =
      AbstractCompactionFilterFactoryJni::getNameMethodId(env);
  if(jname_method_id == nullptr) {
    // exception thrown: NoSuchMethodException or OutOfMemoryError
    return;
  }

  jstring jname =
      (jstring)env->CallObjectMethod(m_jcallback_obj, jname_method_id);
  if(env->ExceptionCheck()) {
    // exception thrown
    return;
  }
  jboolean has_exception = JNI_FALSE;
  m_name = JniUtil::copyString(env, jname, &has_exception);  // also releases jname
  if (has_exception == JNI_TRUE) {
    // exception thrown
    return;
  }

  m_jcreate_compaction_filter_methodid =
      AbstractCompactionFilterFactoryJni::getCreateCompactionFilterMethodId(env);
  if(m_jcreate_compaction_filter_methodid == nullptr) {
    // exception thrown: NoSuchMethodException or OutOfMemoryError
    return;
  }
}

const char* CompactionFilterFactoryJniCallback::Name() const {
  return m_name.get();
}

std::unique_ptr<CompactionFilter> CompactionFilterFactoryJniCallback::CreateCompactionFilter(
    const CompactionFilter::Context& context) {
  jboolean attached_thread = JNI_FALSE;
  JNIEnv* env = getJniEnv(&attached_thread);
  assert(env != nullptr);

  jlong addr_compaction_filter = env->CallLongMethod(m_jcallback_obj,
      m_jcreate_compaction_filter_methodid,
      static_cast<jboolean>(context.is_full_compaction),
      static_cast<jboolean>(context.is_manual_compaction));

  if(env->ExceptionCheck()) {
    // exception thrown from CallLongMethod
    env->ExceptionDescribe();  // print out exception to stderr
    releaseJniEnv(attached_thread);
    return nullptr;
  }

  auto* const cff = reinterpret_cast<CompactionFilter*>(addr_compaction_filter);

  releaseJniEnv(attached_thread);

  return std::unique_ptr<CompactionFilter>(cff);
}

It is not clear how to read this stack trace for identifying the problem. I would appreciate to receive a little suggestion for understand how fix the problem and read the stack trace.