Skip to content

Commit

Permalink
Make trycatch sfinae work on msvc
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Mar 18, 2020
1 parent 3e3e0af commit 189915a
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions gen/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,20 +210,17 @@ fn write_include_cxxbridge(out: &mut OutFile, apis: &[Api], types: &Types) {
if needs_trycatch {
out.begin_block("namespace behavior");
out.include.exception = true;
writeln!(out, "struct trycatch {{");
writeln!(out, " template <typename T> trycatch(T);");
writeln!(out, " static char use_default;");
writeln!(out, "}};");
writeln!(out, "class missing {{}};");
writeln!(out, "missing trycatch(...);");
writeln!(out);
writeln!(out, "template <typename Try, typename Fail,");
writeln!(
out,
" typename = decltype(trycatch(std::declval<Try>()).use_default)>",
);
writeln!(out, "template <typename Try, typename Fail>");
writeln!(out, "static typename std::enable_if<");
writeln!(
out,
"static void trycatch(Try &&func, Fail &&fail) noexcept try {{",
" std::is_same<decltype(trycatch(std::declval<Try>(), std::declval<Fail>())),",
);
writeln!(out, " missing>::value>::type");
writeln!(out, "trycatch(Try &&func, Fail &&fail) noexcept try {{");
writeln!(out, " func();");
writeln!(out, "}} catch (const ::std::exception &e) {{");
writeln!(out, " fail(e.what());");
Expand Down

0 comments on commit 189915a

Please sign in to comment.