Skip to content

Commit

Permalink
Use auto ref for OutputRange parameters. (#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
jondegenhardt authored Oct 7, 2018
1 parent 6a6f9b7 commit 1e1bd00
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 1 addition & 1 deletion csv2tsv/src/csv2tsv.d
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void csv2tsvFiles(in Csv2tsvOptions cmdopt, in string[] inputFiles)
* line number where the error was identified.
*/
void csv2tsv(InputRange, OutputRange)
(ref InputRange inputStream, ref OutputRange outputStream,
(auto ref InputRange inputStream, auto ref OutputRange outputStream,
string filename = "(none)", size_t currFileLineNumber = 0,
const char csvQuote = '"', const char csvDelim = ',', const char tsvDelim = '\t',
string tsvDelimReplacement = " ",
Expand Down
2 changes: 1 addition & 1 deletion tsv-append/src/tsv-append.d
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ struct TsvAppendOptions

/** tsvAppend implements the basic functionality of the tsv-append program.
*/
void tsvAppend(OutputRange)(TsvAppendOptions cmdopt, OutputRange outputStream)
void tsvAppend(OutputRange)(TsvAppendOptions cmdopt, auto ref OutputRange outputStream)
if (isOutputRange!(OutputRange, char))
{
bool headerWritten = false;
Expand Down
15 changes: 8 additions & 7 deletions tsv-sample/src/tsv-sample.d
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ struct TsvSampleOptions
}
/** Invokes the appropriate sampling routine based on the command line arguments.
*/
void tsvSample(OutputRange)(TsvSampleOptions cmdopt, ref OutputRange outputStream)
void tsvSample(OutputRange)(TsvSampleOptions cmdopt, auto ref OutputRange outputStream)
if (isOutputRange!(OutputRange, char))
{
if (cmdopt.srsWithReplacement)
{
Expand Down Expand Up @@ -381,7 +382,7 @@ void tsvSample(OutputRange)(TsvSampleOptions cmdopt, ref OutputRange outputStrea
* weights would no longer be consistent run-to-run.
*/
void bernoulliSampling(Flag!"generateRandomAll" generateRandomAll, OutputRange)
(TsvSampleOptions cmdopt, ref OutputRange outputStream)
(TsvSampleOptions cmdopt, auto ref OutputRange outputStream)
if (isOutputRange!(OutputRange, char))
{
import std.format : formatValue, singleSpec;
Expand Down Expand Up @@ -468,7 +469,7 @@ if (isOutputRange!(OutputRange, char))
* zero are output.
*/
void distinctSampling(Flag!"generateRandomAll" generateRandomAll, OutputRange)
(TsvSampleOptions cmdopt, ref OutputRange outputStream)
(TsvSampleOptions cmdopt, auto ref OutputRange outputStream)
if (isOutputRange!(OutputRange, char))
{
import std.algorithm : splitter;
Expand Down Expand Up @@ -631,7 +632,7 @@ if (isOutputRange!(OutputRange, char))
* https://en.wikipedia.org/wiki/Reservoir_sampling#Algorithm_R.
*/
void reservoirSampling(Flag!"isWeighted" isWeighted, OutputRange)
(TsvSampleOptions cmdopt, ref OutputRange outputStream)
(TsvSampleOptions cmdopt, auto ref OutputRange outputStream)
if (isOutputRange!(OutputRange, char))
{
import std.container.array;
Expand Down Expand Up @@ -750,7 +751,7 @@ if (isOutputRange!(OutputRange, char))
* simply iterates over the input lines generating the values. The weighted random
* values are generated with the same formula used by reservoirSampling.
*/
void generateWeightedRandomValuesInorder(OutputRange)(TsvSampleOptions cmdopt, ref OutputRange outputStream)
void generateWeightedRandomValuesInorder(OutputRange)(TsvSampleOptions cmdopt, auto ref OutputRange outputStream)
if (isOutputRange!(OutputRange, char))
{
import std.format : formatValue, singleSpec;
Expand Down Expand Up @@ -826,7 +827,7 @@ if (isOutputRange!(OutputRange, char))
* printing does not make sense. Order consistency matters only in the rare case when
* multiple randomizations are being done with the same static seed.
*/
void randomizeLines(Flag!"isWeighted" isWeighted, OutputRange)(TsvSampleOptions cmdopt, ref OutputRange outputStream)
void randomizeLines(Flag!"isWeighted" isWeighted, OutputRange)(TsvSampleOptions cmdopt, auto ref OutputRange outputStream)
if (isOutputRange!(OutputRange, char))
{
import std.algorithm : min, sort, splitter;
Expand Down Expand Up @@ -948,7 +949,7 @@ if (isOutputRange!(OutputRange, char))
* until the desired number of samples (--n|num) has been output. Output continues
* indefinitely if a sample size was not provided.
*/
void simpleRandomSamplingWithReplacement(OutputRange)(TsvSampleOptions cmdopt, ref OutputRange outputStream)
void simpleRandomSamplingWithReplacement(OutputRange)(TsvSampleOptions cmdopt, auto ref OutputRange outputStream)
if (isOutputRange!(OutputRange, char))
{
import std.algorithm : each, min, sort, splitter;
Expand Down

0 comments on commit 1e1bd00

Please sign in to comment.