From 2113258e86961517348d908d90f5cbe6c8f4c6f3 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Wed, 2 Feb 2022 19:24:24 +0000 Subject: [PATCH 1/2] Demonstrate deduction guides for normal_distribution. --- include/boost/math/distributions/normal.hpp | 14 ++++++++++++++ test/Jamfile.v2 | 2 ++ 2 files changed, 16 insertions(+) diff --git a/include/boost/math/distributions/normal.hpp b/include/boost/math/distributions/normal.hpp index b9697ebb08..73ada53b6f 100644 --- a/include/boost/math/distributions/normal.hpp +++ b/include/boost/math/distributions/normal.hpp @@ -71,6 +71,20 @@ class normal_distribution typedef normal_distribution normal; +// +// Deduction guides, note we don't check the +// value of __cpp_deduction_guides, just assume +// they work as advertised, even if this is pre-final C++17. +// +#ifdef __cpp_deduction_guides + +template +normal_distribution(RealType, RealType)->normal_distribution::type>; +template +normal_distribution(RealType)->normal_distribution::type>; + +#endif + #ifdef _MSC_VER #pragma warning(push) #pragma warning(disable:4127) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 6d5667a295..828f22663b 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -877,6 +877,8 @@ test-suite distribution_tests : [ run test_signed_zero.cpp ../../test/build//boost_unit_test_framework ] [ run complex_test.cpp ../../test/build//boost_unit_test_framework ] + [ compile test_normal_dist_deduction_guides.cpp : [ requires cpp_deduction_guides ] ] + ; test-suite mp : From 50434445a4367651eb1f525840e317051537b2c0 Mon Sep 17 00:00:00 2001 From: jzmaddock Date: Wed, 2 Feb 2022 19:28:53 +0000 Subject: [PATCH 2/2] Add missing test case. --- test/test_normal_dist_deduction_guides.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test/test_normal_dist_deduction_guides.cpp diff --git a/test/test_normal_dist_deduction_guides.cpp b/test/test_normal_dist_deduction_guides.cpp new file mode 100644 index 0000000000..baa4ffb220 --- /dev/null +++ b/test/test_normal_dist_deduction_guides.cpp @@ -0,0 +1,18 @@ +// (C) Copyright John Maddock 2022. +// Use, modification and distribution are subject to the +// Boost Software License, Version 1.0. (See accompanying file +// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include + +int main() +{ + using namespace boost::math; + + normal_distribution n; + static_assert(std::is_same::value); + normal_distribution n2(2); + static_assert(std::is_same::value); + normal_distribution n3(2, 3); + static_assert(std::is_same::value); +}