Parcourir la source

Drop the custom result type

default_compile_flags
vector-of-bool il y a 3 ans
Parent
révision
964136f984
3 fichiers modifiés avec 8 ajouts et 26 suppressions
  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 Voir le fichier

@@ -15,7 +15,8 @@ builder dds::cli::create_project_builder(const dds::cli::options& opts) {
.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 repo_path = opts.pkg_cache_dir.value_or(pkg_cache::default_local_path());


+ 1
- 1
src/dds/sdist/dist.cpp Voir le fichier

@@ -123,7 +123,7 @@ sdist dds::create_sdist_in_dir(path_ref out, const sdist_params& params) {
sdist sdist::from_directory(path_ref where) {
auto pkg_man = package_manifest::load_from_directory(where);
// 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>(
"The given directory [{}] does not contain a package manifest file. All source "
"distribution directories are required to contain a package manifest.",

+ 5
- 24
src/dds/util/result.hpp Voir le fichier

@@ -15,28 +15,12 @@ namespace dds {
using boost::leaf::current_error;
using boost::leaf::error_id;
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
@@ -92,6 +76,3 @@ struct e_parse_error {
auto NEO_CONCAT(_err_info_, __LINE__) = boost::leaf::on_error(DDS_E_ARG(__VA_ARGS__))

} // namespace dds

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

Chargement…
Annuler
Enregistrer