extract.detail.hpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#pragma once


#include <span>


namespace felspar::parse::binary::detail {


    template<typename T>
    T native_extract(std::span<std::byte const, sizeof(T)> const s) noexcept {
        T into;
        std::copy(
                s.begin(), s.end(),
                std::as_writable_bytes(std::span{&into, 1}).begin());
        return into;
    }
    template<typename T>
    T non_native_extract(std::span<std::byte const, sizeof(T)> const s) noexcept {
        T into;
        std::copy(
                s.rbegin(), s.rend(),
                std::as_writable_bytes(std::span{&into, 1}).begin());
        return into;
    }


}