vendredi 1 juin 2018

Why wont std::bind work with a std::filesystem::path and std::ostream?

I am currently trying to write a program that makes use of std::bind with a std::filesystem::path and std::ostream, both as references, as follows:

#include <functional>
#include <filesystem>
#include <ostream>
#include <iostream>

struct Buggy{
    static void something(const std::filesystem::path &path, std::ostream &out);
    void bind();
};

void Buggy::bind(){
    auto function = std::bind(&Buggy::something, std::placeholders::_1, std::cout);
    function(std::filesystem::path("./"));
}

void Buggy::something(const std::filesystem::path &path, std::ostream &out){
    out << path.string() << std::endl;
}

int main(){
    Buggy buggy;
    buggy.bind();
}

I expect this code to simply output "./", but instead, it gives me massive template errors. Why is this? My use of std::bind looks correct to me. I am compiling with g++ --std=c++17 bug4.cpp -o bug4 -lstdc++fs on Linux.

I am unable to read the template errors because they are so intermixed with implementation details of this standard library. I have tried compiling with clang and gcc, both of which give similar errors. Searching via a search engine gives no useful results.

Aucun commentaire:

Enregistrer un commentaire