Skip to content

Commit

Permalink
Also support <filesystem> as well as <experimental/filesystem>
Browse files Browse the repository at this point in the history
The change for <coroutine> vs. <experimental/coroutine> is
replicated for <filesystem> in this patch. In addition,
the std::experimental namespace is replaced by cppcoro:: namespace
in a few more places.
  • Loading branch information
andreasbuhr committed Oct 10, 2020
1 parent 49da236 commit 06b3bab
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 20 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -714,15 +714,15 @@ namespace cppcoro
{
public:
bool await_ready() const noexcept;
bool await_suspend(std::experimental::coroutine_handle<> awaiter) noexcept;
bool await_suspend(cppcoro::coroutine_handle<> awaiter) noexcept;
void await_resume() const noexcept;
};

class async_mutex_scoped_lock_operation
{
public:
bool await_ready() const noexcept;
bool await_suspend(std::experimental::coroutine_handle<> awaiter) noexcept;
bool await_suspend(cppcoro::coroutine_handle<> awaiter) noexcept;
[[nodiscard]] async_mutex_lock await_resume() const noexcept;
};

Expand Down Expand Up @@ -836,7 +836,7 @@ namespace cppcoro
async_manual_reset_event_operation(async_manual_reset_event& event) noexcept;

bool await_ready() const noexcept;
bool await_suspend(std::experimental::coroutine_handle<> awaiter) noexcept;
bool await_suspend(cppcoro::coroutine_handle<> awaiter) noexcept;
void await_resume() const noexcept;
};
}
Expand Down Expand Up @@ -904,7 +904,7 @@ namespace cppcoro
async_auto_reset_event_operation(const async_auto_reset_event_operation& other) noexcept;
bool await_ready() const noexcept;
bool await_suspend(std::experimental::coroutine_handle<> awaiter) noexcept;
bool await_suspend(cppcoro::coroutine_handle<> awaiter) noexcept;
void await_resume() const noexcept;
};
Expand Down Expand Up @@ -1389,7 +1389,7 @@ namespace cppcoro
schedule_operation(static_thread_pool* tp) noexcept;
bool await_ready() noexcept;
bool await_suspend(std::experimental::coroutine_handle<> h) noexcept;
bool await_suspend(cppcoro::coroutine_handle<> h) noexcept;
bool await_resume() noexcept;
private:
Expand Down Expand Up @@ -1546,7 +1546,7 @@ namespace cppcoro
schedule_operation& operator=(const schedule_operation&) noexcept;

bool await_ready() const noexcept;
void await_suspend(std::experimental::coroutine_handle<> awaiter) noexcept;
void await_suspend(cppcoro::coroutine_handle<> awaiter) noexcept;
void await_resume() noexcept;
};

Expand All @@ -1560,7 +1560,7 @@ namespace cppcoro
timed_schedule_operation& operator=(timed_schedule_operation&&) = delete;

bool await_ready() const noexcept;
void await_suspend(std::experimental::coroutine_handle<> awaiter);
void await_suspend(cppcoro::coroutine_handle<> awaiter);
void await_resume();
};

Expand Down Expand Up @@ -1591,12 +1591,12 @@ Example:
#include <cppcoro/io_service.hpp>
#include <cppcoro/read_only_file.hpp>
#include <experimental/filesystem>
#include <cppcoro/filesystem.hpp>
#include <memory>
#include <algorithm>
#include <iostream>
namespace fs = std::experimental::filesystem;
namespace fs = cppcoro::filesystem;
cppcoro::task<std::uint64_t> count_lines(cppcoro::io_service& ioService, fs::path path)
{
Expand Down Expand Up @@ -1740,7 +1740,7 @@ namespace cppcoro
file_read_operation(file_read_operation&& other) noexcept;
bool await_ready() const noexcept;
bool await_suspend(std::experimental::coroutine_handle<> awaiter);
bool await_suspend(cppcoro::coroutine_handle<> awaiter);
std::size_t await_resume();
};
Expand All @@ -1752,7 +1752,7 @@ namespace cppcoro
file_write_operation(file_write_operation&& other) noexcept;
bool await_ready() const noexcept;
bool await_suspend(std::experimental::coroutine_handle<> awaiter);
bool await_suspend(cppcoro::coroutine_handle<> awaiter);
std::size_t await_resume();
};
Expand All @@ -1774,7 +1774,7 @@ namespace cppcoro
[[nodiscard]]
static read_only_file open(
io_service& ioService,
const std::experimental::filesystem::path& path,
const cppcoro::filesystem::path& path,
file_share_mode shareMode = file_share_mode::read,
file_buffering_mode bufferingMode = file_buffering_mode::default_);

Expand All @@ -1787,7 +1787,7 @@ namespace cppcoro
[[nodiscard]]
static write_only_file open(
io_service& ioService,
const std::experimental::filesystem::path& path,
const cppcoro::filesystem::path& path,
file_open_mode openMode = file_open_mode::create_or_open,
file_share_mode shareMode = file_share_mode::none,
file_buffering_mode bufferingMode = file_buffering_mode::default_);
Expand All @@ -1801,7 +1801,7 @@ namespace cppcoro
[[nodiscard]]
static read_write_file open(
io_service& ioService,
const std::experimental::filesystem::path& path,
const cppcoro::filesystem::path& path,
file_open_mode openMode = file_open_mode::create_or_open,
file_share_mode shareMode = file_share_mode::none,
file_buffering_mode bufferingMode = file_buffering_mode::default_);
Expand Down Expand Up @@ -2794,7 +2794,7 @@ coroutine.

A type that satisfies `Awaiter<T>` must have, for an instance of the type, `awaiter`:
- `awaiter.await_ready()` -> `bool`
- `awaiter.await_suspend(std::experimental::coroutine_handle<void>{})` -> `void` or `bool` or `std::experimental::coroutine_handle<P>` for some `P`.
- `awaiter.await_suspend(cppcoro::coroutine_handle<void>{})` -> `void` or `bool` or `cppcoro::coroutine_handle<P>` for some `P`.
- `awaiter.await_resume()` -> `T`

Any type that implements the `Awaiter<T>` concept also implements the `Awaitable<T>` concept.
Expand Down
2 changes: 2 additions & 0 deletions include/cppcoro/coroutine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace cppcoro {

using suspend_always = std::suspend_always;
using suspend_never = std::suspend_never;
static inline auto noop_coroutine() { return std::noop_coroutine(); }
}

#elif __has_include(<experimental/coroutine>)
Expand All @@ -23,6 +24,7 @@ namespace cppcoro {

using suspend_always = std::experimental::suspend_always;
using suspend_never = std::experimental::suspend_never;
static inline auto noop_coroutine() { return std::experimental::noop_coroutine(); }
}

#else
Expand Down
2 changes: 1 addition & 1 deletion include/cppcoro/file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# include <cppcoro/detail/win32.hpp>
#endif

#include <experimental/filesystem>
#include <cppcoro/filesystem.hpp>

namespace cppcoro
{
Expand Down
24 changes: 24 additions & 0 deletions include/cppcoro/filesystem.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef CPPCORO_FILESYSTEM_HPP_INCLUDED
#define CPPCORO_FILESYSTEM_HPP_INCLUDED

#if __has_include(<filesystem>)

#include <filesystem>

namespace cppcoro {
namespace filesystem = std::filesystem;
}

#elif __has_include(<experimental/filesystem>)

#include <experimental/filesystem>

namespace cppcoro {
namespace filesystem = std::experimental::filesystem;
}

#else
#error Cppcoro requires a C++20 compiler with filesystem support
#endif

#endif
2 changes: 1 addition & 1 deletion include/cppcoro/net/socket_accept_operation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

# include <atomic>
# include <optional>
# include <experimental/coroutine>
# include <cppcoro/coroutine.hpp>

namespace cppcoro
{
Expand Down
2 changes: 1 addition & 1 deletion include/cppcoro/read_only_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <cppcoro/file_share_mode.hpp>
#include <cppcoro/file_buffering_mode.hpp>

#include <experimental/filesystem>
#include <cppcoro/filesystem.hpp>

namespace cppcoro
{
Expand Down
2 changes: 1 addition & 1 deletion include/cppcoro/read_write_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include <cppcoro/file_buffering_mode.hpp>
#include <cppcoro/file_open_mode.hpp>

#include <experimental/filesystem>
#include <cppcoro/filesystem.hpp>

namespace cppcoro
{
Expand Down
2 changes: 1 addition & 1 deletion include/cppcoro/write_only_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <cppcoro/file_buffering_mode.hpp>
#include <cppcoro/file_open_mode.hpp>

#include <experimental/filesystem>
#include <cppcoro/filesystem.hpp>

namespace cppcoro
{
Expand Down

0 comments on commit 06b3bab

Please sign in to comment.