Ignore:
Timestamp:
05/06/25 23:06:50 (2 days ago)
Author:
Maciej Komosinski
Message:

Added helper functions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/common/nonstd_span.h

    r1183 r1340  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 2019-2022  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 2019-2024  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
    55#ifndef _NONSTD_SPAN_H_
    66#define _NONSTD_SPAN_H_
     7
     8#include <string>
     9#include <vector>
    710
    811// Remove this and use std::span when available (c++20)
     
    4447};
    4548
     49inline std::string stringFromSpan(const span<uint8_t>& s) { return std::string(s.begin(), s.end()); }
     50inline std::string stringFromSpan(const span<char>& s) { return std::string(s.begin(), s.end()); }
     51// in both lines below, in the last argument, &*v.end() was replaced by front+size, because the debugging+extensive checking version of the STL library with std::vector complained when calling &*v.end().
     52inline span<uint8_t> spanFromVector(std::vector<uint8_t>& v) { return span<uint8_t>(&v.front(), ((uint8_t*)&v.front())+v.size()); }
     53inline span<uint8_t> spanFromVector(std::vector<char>& v) { return span<uint8_t>((uint8_t*)&v.front(), ((uint8_t*)&v.front())+v.size()); }
     54
    4655#endif
Note: See TracChangeset for help on using the changeset viewer.