-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ostream hex support for DynamicArrayOf
- Loading branch information
Showing
3 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#pragma once | ||
#include "DynamicArrayOf.h" | ||
|
||
#include <iomanip> | ||
#include <ostream> | ||
|
||
namespace array19 { | ||
|
||
template<class T> struct AsHex { | ||
const DynamicArrayOf<T>& a; | ||
|
||
template<class Chr, class Traits> | ||
friend auto operator<<(std::basic_ostream<Chr, Traits>& out, AsHex<T>&& a) -> decltype(out)& { | ||
out << "["; | ||
bool first = true; | ||
for (auto& v : a.a) { | ||
if (first) | ||
first = false; | ||
else | ||
out << ", "; | ||
out << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex << std::internal << +v; | ||
} | ||
return out << std::dec << "]"; | ||
} | ||
}; | ||
|
||
} // namespace array19 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters