-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Stdio Design] Designates Initializers & Extensions #62
Comments
2 Concepts for
|
Designated initializers don't work on MSVC, not sure if a implementation error or if gcc is to leniant. Relevant for #67. |
Implemented in the the reference implementation for gcc. |
Two weeks ago I might have questioned if we could get FILE* past the committee bc it's using a C construct in a c++ interface. But the format library just had a positive reception for that from LEWG so it seems possible. |
Not sure -- is there a snippet we can put in godbolt to see what clang says? |
The namespace detail {
#if defined(__unix__)
using native_stream_handle = int;
struct default_stderr { static int get() {return STDERR_FILENO;} };
struct default_stdout { static int get() {return STDOUT_FILENO;} };
struct default_stdin { static int get() {return STDIN_FILENO;} };
#else
using native_stream_handle = HANDLE;
struct default_stderr { static HANDLE get() {return GetStdHandle(STD_ERROR_HANDLE);} };
struct default_stdout { static HANDLE get() {return GetStdHandle(STD_OUTPUT_HANDLE);} };
struct default_stdin { static HANDLE get() {return GetStdHandle(STD_INPUT_HANDLE);} };
#endif
} template<typename In = detail::default_stdin, typename Out = detail::default_stdout, typename Err = detail::default_stderr>
requires(
requires(In in) { { process_io_traits<std::remove_reference_t<In >>::get_readable_handle(in) } -> std::convertible_to<detail::native_stream_handle>;}
&& requires(Out out) { { process_io_traits<std::remove_reference_t<Out>>::get_writable_handle(out)} -> std::convertible_to<detail::native_stream_handle>;}
&& requires(Err err) { { process_io_traits<std::remove_reference_t<Err>>::get_writable_handle(err)} -> std::convertible_to<detail::native_stream_handle>;}
)
struct process_io
{
In in = {};
Out out = {};
Err err = {};
//...
]; |
I wasn't able to reproduce the issue with a simple example, but I think this is semantically correct. A very much simplified example works on gce. |
@JeffGarland Should ramblings like this go into the std proposal?
1 Designated initializers
We COULD use designated initializers like so:
This easens the syntax, but captures by copy. In
boost::process
everything is captured by reference, but conceptually, i actually don't dislike this. If we use this with a pipe, what you usually want to to assign one pipe end to the child, and then close it on the father. This would look like this:The downside is that a
pstream
is copyable (which clones the handle), so that the naive solution would lead to potential deadlocks:This could be avoided by making pipes not-copyable, which might be the best solution, since
fstream
can't be copied either. There is however a difference between pipes & files, in that files may be reopened by their name, while there's no way to do so with a pipe. But, I don't see any application for this - plus, if we can get the native_handle from a pipe and can construct another pipe from the handle, you can easily implement this corner case on your own.The text was updated successfully, but these errors were encountered: