diff --git a/main b/main index 7eb0e19..7e467d5 100755 Binary files a/main and b/main differ diff --git a/main.cc b/main.cc index a94c260..8bfcd31 100755 --- a/main.cc +++ b/main.cc @@ -9,8 +9,10 @@ int main() { auto buf = check_output({"echo", "\"It works!\""}); std::cout << buf.buf.data() << " :: " << buf.length << std::endl; - auto buf2 = check_output("cat subprocess.hpp"); - std::cout << buf2.buf.data() << " :: " << buf2.length << std::endl; + buf = check_output("cat subprocess.hpp"); + //std::cout << buf2.buf.data() << " :: " << buf2.length << std::endl; + // + return 0; } diff --git a/subprocess.hpp b/subprocess.hpp index 297834e..9630053 100755 --- a/subprocess.hpp +++ b/subprocess.hpp @@ -279,6 +279,22 @@ public: Buffer(size_t cap) { buf.resize(cap); } void add_cap(size_t cap) { buf.resize(cap); } +#if 0 + Buffer(const Buffer& other): + buf(other.buf), + length(other.length) + { + std::cout << "COPY" << std::endl; + } + + Buffer(Buffer&& other): + buf(std::move(other.buf)), + length(other.length) + { + std::cout << "MOVE" << std::endl; + } +#endif + public: std::vector buf; size_t length = 0; @@ -1007,7 +1023,7 @@ namespace detail if (retcode) { throw CalledProcessError("Command failed"); } - return (res.first); + return std::move(res.first); } } @@ -1021,13 +1037,13 @@ int call(Args&&... args) template OutBuffer check_output(std::initializer_list plist, Args&&... args) { - return detail::check_output_impl(plist, std::forward(args)...); + return (detail::check_output_impl(plist, std::forward(args)...)); } template OutBuffer check_output(const std::string& arg, Args&&... args) { - return detail::check_output_impl(arg, std::forward(args)...); + return (detail::check_output_impl(arg, std::forward(args)...)); } };