This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of Resolved status.
initializer_list constructor for piecewise_constant_distributionSection: 29.5.9.6.2 [rand.dist.samp.pconst] Status: Resolved Submitter: Daniel Krügler Opened: 2008-08-22 Last modified: 2016-01-28
Priority: Not Prioritized
View all other issues in [rand.dist.samp.pconst].
View all issues with Resolved status.
Discussion:
During the Sophia Antipolis meeting it was decided to separate from
794(i) a subrequest that adds initializer list support to
piecewise_constant_distribution, specifically, the issue proposed
to add a c'tor taking a initializer_list<double> and a Callable to evaluate
weight values. For consistency with the remainder of this class and
the remainder of the initializer_list-aware library the author decided to
change the list argument type to the template parameter RealType
instead. For the reasoning to use Func instead of Func&& as c'tor
function argument see issue 793(i).
Proposed resolution:
Non-concept version of the proposed resolution
In 29.5.9.6.2 [rand.dist.samp.pconst]/1, class piecewise_constant_distribution,
just before the member declaration
explicit piecewise_constant_distribution(const param_type& parm);
insert
template<typename Func> piecewise_constant_distribution(initializer_list<RealType> bl, Func fw);
Between p.4 and p.5 of the same section insert a series of new paragraphs nominated below as [p5_1], [p5_2], and [p5_3] as part of the new member description:
template<typename Func> piecewise_constant_distribution(initializer_list<RealType> bl, Func fw);[p5_1] Complexity: Exactly
nf = max(bl.size(), 1) - 1invocations offw.[p5_2] Requires:
fwshall be callable with one argument of typeRealType, and shall return values of a type convertible todouble;- The relation
0 < S = w0+. . .+wn-1shall hold. For all sampled valuesxkdefined below,fw(xk)shall return a weight valuewkthat is non-negative, non-NaN, and non-infinity;- If
nf > 0letbk = *(bl.begin() + k), k = 0, . . . , bl.size()-1and the following relations shall hold fork = 0, . . . , nf-1: bk < bk+1.[p5_3] Effects:
If
nf == 0,
- lets the sequence
whave lengthn = 1and consist of the single valuew0 = 1, and- lets the sequence
bhave lengthn+1withb0 = 0andb1 = 1.Otherwise,
- sets
n = nf, and[bl.begin(), bl.end())shall form the sequencebof lengthn+1, andlets the sequences
whave lengthnand for eachk = 0, . . . ,n-1, calculates:xk = 0.5*(bk+1 + bk) wk = fw(xk)
Constructs a
piecewise_constant_distributionobject with the above computed sequencebas the interval boundaries and with the probability densities:ρk = wk/(S * (bk+1 - bk)) for k = 0, . . . , n-1.
Concept version of the proposed resolution
In 29.5.9.6.2 [rand.dist.samp.pconst]/1, class piecewise_constant_distribution,
just before the member declaration
explicit piecewise_constant_distribution(const param_type& parm);
insert
template<Callable<auto, RealType> Func> requires Convertible<Func::result_type, double> piecewise_constant_distribution(initializer_list<RealType> bl, Func fw);
Between p.4 and p.5 of the same section insert a series of new paragraphs nominated below as [p5_1], [p5_2], and [p5_3] as part of the new member description:
template<Callable<auto, RealType> Func> requires Convertible<Func::result_type, double> piecewise_constant_distribution(initializer_list<RealType> bl, Func fw);[p5_1] Complexity: Exactly
nf = max(bl.size(), 1) - 1invocations offw.[p5_2] Requires:
- The relation
0 < S = w0+. . .+wn-1shall hold. For all sampled valuesxkdefined below,fw(xk)shall return a weight valuewkthat is non-negative, non-NaN, and non-infinity;- If
nf > 0letbk = *(bl.begin() + k), k = 0, . . . , bl.size()-1and the following relations shall hold fork = 0, . . . , nf-1: bk < bk+1.[p5_3] Effects:
If
nf == 0,
- lets the sequence
whave lengthn = 1and consist of the single valuew0 = 1, and- lets the sequence
bhave lengthn+1withb0 = 0andb1 = 1.Otherwise,
- sets
n = nf, and[bl.begin(), bl.end())shall form the sequencebof lengthn+1, andlets the sequences
whave lengthnand for eachk = 0, . . . ,n-1, calculates:xk = 0.5*(bk+1 + bk) wk = fw(xk)
Constructs a
piecewise_constant_distributionobject with the above computed sequencebas the interval boundaries and with the probability densities:ρk = wk/(S * (bk+1 - bk)) for k = 0, . . . , n-1.
Rationale:
Addressed by N2836 "Wording Tweaks for Concept-enabled Random Number Generation in C++0X".