Browse Source

Drop the custom result type

default_compile_flags
vector-of-bool 3 years ago
parent
commit
964136f984
3 changed files with 8 additions and 26 deletions
  1. +2
    -1
      src/dds/cli/cmd/build_common.cpp
  2. +1
    -1
      src/dds/sdist/dist.cpp
  3. +5
    -24
      src/dds/util/result.hpp

+ 2
- 1
src/dds/cli/cmd/build_common.cpp View File

.enable_warnings = !opts.disable_warnings, .enable_warnings = !opts.disable_warnings,
}; };


auto man = package_manifest::load_from_directory(opts.project_dir).value_or(package_manifest{});
auto man
= value_or(package_manifest::load_from_directory(opts.project_dir), package_manifest{});
auto cat_path = opts.pkg_db_dir.value_or(pkg_db::default_path()); auto cat_path = opts.pkg_db_dir.value_or(pkg_db::default_path());
auto repo_path = opts.pkg_cache_dir.value_or(pkg_cache::default_local_path()); auto repo_path = opts.pkg_cache_dir.value_or(pkg_cache::default_local_path());



+ 1
- 1
src/dds/sdist/dist.cpp View File

sdist sdist::from_directory(path_ref where) { sdist sdist::from_directory(path_ref where) {
auto pkg_man = package_manifest::load_from_directory(where); auto pkg_man = package_manifest::load_from_directory(where);
// Code paths should only call here if they *know* that the sdist is valid // Code paths should only call here if they *know* that the sdist is valid
if (!pkg_man.has_value()) {
if (!pkg_man) {
throw_user_error<errc::invalid_pkg_filesystem>( throw_user_error<errc::invalid_pkg_filesystem>(
"The given directory [{}] does not contain a package manifest file. All source " "The given directory [{}] does not contain a package manifest file. All source "
"distribution directories are required to contain a package manifest.", "distribution directories are required to contain a package manifest.",

+ 5
- 24
src/dds/util/result.hpp View File

using boost::leaf::current_error; using boost::leaf::current_error;
using boost::leaf::error_id; using boost::leaf::error_id;
using boost::leaf::new_error; using boost::leaf::new_error;
using boost::leaf::result;


template <typename T>
class result : public boost::leaf::result<T> {
public:
using result_base = boost::leaf::result<T>;

using result_base::result;

template <neo::convertible_to<result_base> Other>
result(Other&& oth) noexcept
: result_base(static_cast<result_base>(NEO_FWD(oth))) {}

constexpr bool has_value() const noexcept { return !!*this; }
template <typename U>
constexpr T value_or(U&& u) const noexcept {
if (has_value()) {
return **this;
} else {
return T(NEO_FWD(u));
}
}
};
template <typename T, neo::convertible_to<T> U>
constexpr T value_or(const result<T>& res, U&& arg) {
return res ? res.value() : static_cast<T>(arg);
}


/** /**
* @brief Error object representing a captured system_error exception * @brief Error object representing a captured system_error exception
auto NEO_CONCAT(_err_info_, __LINE__) = boost::leaf::on_error(DDS_E_ARG(__VA_ARGS__)) auto NEO_CONCAT(_err_info_, __LINE__) = boost::leaf::on_error(DDS_E_ARG(__VA_ARGS__))


} // namespace dds } // namespace dds

template <typename T>
struct boost::leaf::is_result_type<dds::result<T>> : std::true_type {};

Loading…
Cancel
Save