Skip to content

Commit

Permalink
use Fence to avoid conflict between alias fmt and string file
Browse files Browse the repository at this point in the history
  • Loading branch information
linkrope committed May 30, 2018
1 parent c7d3835 commit 640a8c2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion example.d
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import util.log;

string details()
{
import std.stdio;
import std.stdio : writeln;

writeln("lazy evaluation");
return "details";
Expand Down
11 changes: 8 additions & 3 deletions src/util/log.d
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,29 @@ struct Log
alias error = append!(LogLevel.error);
alias fatal = append!(LogLevel.fatal);

private struct Fence {} // argument cannot be provided explicitly

template append(LogLevel level)
{
void append(alias fmt, size_t line = __LINE__, string file = __FILE__, A...)(lazy A args)
void append(alias fmt, Fence _ = Fence(), string file = __FILE__, size_t line = __LINE__, A...)
(lazy A args)
if (isSomeString!(typeof(fmt)))
{
static if (!level.disabled)
if (level & levels)
_append(level, file, line, format!fmt(args));
}

void append(size_t line = __LINE__, string file = __FILE__, Char, A...)(in Char[] fmt, lazy A args)
void append(Fence _ = Fence(), string file = __FILE__, size_t line = __LINE__, Char, A...)
(in Char[] fmt, lazy A args)
{
static if (!level.disabled)
if (level & levels)
_append(level, file, line, format(fmt, args));
}

void append(size_t line = __LINE__, string file = __FILE__, A)(lazy A arg)
void append(Fence _ = Fence(), string file = __FILE__, size_t line = __LINE__, A)
(lazy A arg)
{
static if (!level.disabled)
if (level & levels)
Expand Down

0 comments on commit 640a8c2

Please sign in to comment.