Changeset 1340


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

Added helper functions

Location:
cpp/common
Files:
2 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
  • cpp/common/util-stl.h

    r1288 r1340  
    11// This file is a part of Framsticks SDK.  http://www.framsticks.com/
    2 // Copyright (C) 1999-2023  Maciej Komosinski and Szymon Ulatowski.
     2// Copyright (C) 1999-2025  Maciej Komosinski and Szymon Ulatowski.
    33// See LICENSE.txt for details.
    44
     
    2626        if (it != v.end())
    2727                v.erase(it);
     28}
     29
     30// c++17 implementation of c++20 std::vector::erase_if()
     31template<typename T,typename P> void erase_if(vector<T>& v, P predicate)
     32{
     33        v.erase(std::remove_if(v.begin(), v.end(), predicate), v.end());
    2834}
    2935
Note: See TracChangeset for help on using the changeset viewer.