Skip to content

Commit

Permalink
watchman: watchman::Unit -> folly::Unit
Browse files Browse the repository at this point in the history
Summary: as above

Reviewed By: chadaustin

Differential Revision: D13754366

fbshipit-source-id: 1178a5b7b2c927696d63e7a30db9dbaf94ed3eeb
  • Loading branch information
wez authored and facebook-github-bot committed Jan 25, 2019
1 parent b9c842b commit 7265061
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions Result.h
@@ -1,20 +1,14 @@
/* Copyright 2017-present Facebook, Inc.
* Licensed under the Apache License, Version 2.0 */
#pragma once
#include <folly/Unit.h>
#include <exception>
#include <stdexcept>
#include <system_error>
#include <type_traits>

namespace watchman {

// To avoid some horrible special casing for the void type in template
// metaprogramming we use Unit to denote an uninteresting value type.
struct Unit {
// Lift void -> Unit if T is void, else T
template <typename T>
struct Lift : std::conditional<std::is_same<T, void>::value, Unit, T> {};
};

// Represents the Result of an operation, and thus can hold either
// a value or an error, or neither. This is similar to the folly::Try
Expand Down Expand Up @@ -285,13 +279,13 @@ makeResultWith(Func&& func) {
template <typename Func>
typename std::enable_if<
std::is_same<typename std::result_of<Func()>::type, void>::value,
Result<Unit>>::type
Result<folly::Unit>>::type
makeResultWith(Func&& func) {
try {
func();
return Result<Unit>(Unit{});
return Result<folly::Unit>(folly::Unit{});
} catch (const std::exception& e) {
return Result<Unit>(std::current_exception());
return Result<folly::Unit>(std::current_exception());
}
}
}
2 changes: 1 addition & 1 deletion tests/ResultTest.cpp
Expand Up @@ -89,7 +89,7 @@ void test_error() {
}

using btype = decltype(b);
auto is_unit = std::is_same<typename btype::value_type, Unit>::value;
auto is_unit = std::is_same<typename btype::value_type, folly::Unit>::value;
ok(is_unit, "b has Unit as a value type");

auto c = makeResultWith([] {
Expand Down

0 comments on commit 7265061

Please sign in to comment.