diff --git a/binary_output/binary_output.hpp b/binary_output/binary_output.hpp index f45ddd1..34a27ac 100644 --- a/binary_output/binary_output.hpp +++ b/binary_output/binary_output.hpp @@ -7,19 +7,19 @@ // Normal template -struct binary{ +struct binary { T thing; - binary(T const t):thing(t){} - binary(binary const& c):thing(c.thing){} + binary(T const t):thing(t) {} + binary(binary const& c):thing(c.thing) {} }; template -binary make_binary(T const t){ +binary make_binary(T const t) { return binary(t); } template -std::ostream& operator<<(std::ostream& out, binary const& rhs){ +std::ostream& operator<<(std::ostream& out, binary const& rhs) { static_assert(std::is_pod::value, "Please specialise this function if your type is not POD"); static_assert(!std::is_pointer::value, "Writing pointer"); out.write(reinterpret_cast(&(rhs.thing)), sizeof(rhs.thing)); @@ -27,21 +27,22 @@ std::ostream& operator<<(std::ostream& out, binary const& rhs){ } // Array +// NOTE: it uses references... template -struct binary_arr{ - T const (& thing)[N]; - binary_arr(const T (& t)[N]):thing(t){} - binary_arr(binary_arr const& c):thing(c.thing){} +struct binary_arr { + T const(& thing)[N]; + binary_arr(const T(& t)[N]):thing(t) {} + binary_arr(binary_arr const& c):thing(c.thing) {} }; template -binary_arr make_binary(const T (& t)[N]){ +binary_arr make_binary(const T(& t)[N]) { static_assert(N>=0, "lijp"); return binary_arr(t); } template -std::ostream& operator<<(std::ostream& out, binary_arr const& rhs){ +std::ostream& operator<<(std::ostream& out, binary_arr const& rhs) { static_assert(std::is_pod::value, "Please specialise this function if your type is not POD"); static_assert(!std::is_pointer::value, "Writing pointer"); out.write(reinterpret_cast(&(rhs.thing)), sizeof(rhs.thing)); diff --git a/binary_output/main.cpp b/binary_output/main.cpp index 5b77412..75e669c 100644 --- a/binary_output/main.cpp +++ b/binary_output/main.cpp @@ -1,9 +1,9 @@ #include #include "binary_output.hpp" -int main(){ +int main() { std::cout << make_binary(1684234849) << std::endl; std::cout << make_binary("A c-style array") << std::endl; - return 0; + return 0; }