about summary refs log tree commit diff
path: root/absl/random/distribution_format_traits.h
diff options
context:
space:
mode:
Diffstat (limited to 'absl/random/distribution_format_traits.h')
-rw-r--r--absl/random/distribution_format_traits.h39
1 files changed, 39 insertions, 0 deletions
diff --git a/absl/random/distribution_format_traits.h b/absl/random/distribution_format_traits.h
index 3f28c9069453..3298c2cdb64b 100644
--- a/absl/random/distribution_format_traits.h
+++ b/absl/random/distribution_format_traits.h
@@ -36,6 +36,12 @@
 #include "absl/types/span.h"
 
 namespace absl {
+
+struct IntervalClosedClosedTag;
+struct IntervalClosedOpenTag;
+struct IntervalOpenClosedTag;
+struct IntervalOpenOpenTag;
+
 namespace random_internal {
 
 // ScalarTypeName defines a preferred hierarchy of preferred type names for
@@ -243,6 +249,39 @@ struct DistributionFormatTraits<absl::log_uniform_int_distribution<R>> {
   }
 };
 
+template <typename TagType, typename NumType>
+struct UniformDistributionWrapper;
+
+template <typename TagType, typename NumType>
+struct DistributionFormatTraits<UniformDistributionWrapper<TagType, NumType>> {
+  using distribution_t = UniformDistributionWrapper<TagType, NumType>;
+  using result_t = NumType;
+
+  static constexpr const char* Name() { return "Uniform"; }
+
+  static std::string FunctionName() {
+    return absl::StrCat(Name(), "<", ScalarTypeName<NumType>(), ">");
+  }
+  static std::string FormatArgs(const distribution_t& d) {
+    absl::string_view tag;
+    if (std::is_same<TagType, IntervalClosedClosedTag>::value) {
+      tag = "IntervalClosedClosed";
+    } else if (std::is_same<TagType, IntervalClosedOpenTag>::value) {
+      tag = "IntervalClosedOpen";
+    } else if (std::is_same<TagType, IntervalOpenClosedTag>::value) {
+      tag = "IntervalOpenClosed";
+    } else if (std::is_same<TagType, IntervalOpenOpenTag>::value) {
+      tag = "IntervalOpenOpen";
+    } else {
+      tag = "[[unknown tag type]]";
+    }
+    return absl::StrCat(tag, ", ", (d.min)(), ", ", (d.max)());
+  }
+  static std::string FormatResults(absl::Span<const result_t> results) {
+    return absl::StrJoin(results, ", ");
+  }
+};
+
 }  // namespace random_internal
 }  // namespace absl