Skip to content

Commit

Permalink
stop using std::is_trivially_copyable in Optional.cpp on "[Pytorch] S…
Browse files Browse the repository at this point in the history
…pecialize guts of c10::optional for 32-bit scalars"

c10::optional has non-trivial copy and move operations always. This change specializes it for 32-bit scalars so that it has trivial copy and move operations in that case. Ideally, we would instead rely on P0602 "variant and optional should propagate copy/move triviality" and use `std::optional` (or implement that functionality ourselves). We can't use `std::optional` because we are stuck with C++14. Implementing the full P0602 ourselves would add even more complexity. We could do it, but this should be a helpful first step.

Differential Revision: [D24552280](https://our.internmc.facebook.com/intern/diff/D24552280/)

[ghstack-poisoned]
  • Loading branch information
swolchok committed Nov 4, 2020
1 parent e149edc commit c6d8a51
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions c10/util/Optional.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

#include <type_traits>

static_assert(std::is_trivially_copyable<c10::optional<int>>::value, "c10::optional<int> should be trivially copyable");
static_assert(std::is_trivially_copyable<c10::optional<bool>>::value, "c10::optional<bool> should be trivially copyable");
static_assert(C10_IS_TRIVIALLY_COPYABLE(c10::optional<int>), "c10::optional<int> should be trivially copyable");
static_assert(C10_IS_TRIVIALLY_COPYABLE(c10::optional<bool>), "c10::optional<bool> should be trivially copyable");

0 comments on commit c6d8a51

Please sign in to comment.