Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constexpr string: make it work for older libstdc++ #807

Merged
merged 5 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/install-hemelb-deps/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ runs:
libctemplate-dev
${{ inputs.extra_apt }}

- uses: actions/cache@v2
- uses: actions/cache@v3
id: deps-cache
with:
path: ${{ env.deps_install_prefix }}
Expand Down
30 changes: 30 additions & 0 deletions .github/actions/setup-compilers/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: 'Set CC and CXX env vars for the configured compiler'

inputs:
compiler:
description: 'Use $suite-$version'
required: true

runs:
using: 'composite'
steps:
- name: Set the env vars with some bash
shell: bash
run: |
set -ex
input=${{ inputs.compiler }}
split=(${input//-/ })
suite=${split[0]}
version=${split[1]}
case $suite in
gnu)
echo "CC=gcc-$version" >> $GITHUB_ENV
echo "CXX=g++-$version" >> $GITHUB_ENV
;;
llvm)
echo "CC=clang-$version" >> $GITHUB_ENV
echo "CXX=clang++-$version" >> $GITHUB_ENV
echo "CXXFLAGS=-stdlib=libc++" >> $GITHUB_ENV
echo "LDFLAGS=-stdlib=libc++" >> $GITHUB_ENV
;;
esac
1 change: 1 addition & 0 deletions .github/workflows/gmy-tool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ jobs:
runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
python-version:
- '3.8'
Expand Down
21 changes: 18 additions & 3 deletions .github/workflows/main-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ env:
hemelb_install_prefix: ${{github.workspace}}/install
# VMs have 2 cores, double as compilation often IO bound
CMAKE_BUILD_PARALLEL_LEVEL: 4
# Latest Gnu compiler on Ubuntu 22.04
CC: gcc-12
CXX: g++-12

jobs:
basic-checks:
Expand All @@ -46,9 +43,18 @@ jobs:
name: Build in fluid-only mode
runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
compiler: [gnu-11, gnu-12, gnu-13]

steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-compilers
with:
compiler: ${{ matrix.compiler }}

- uses: ./.github/actions/install-hemelb-deps
with:
name: fluidonly
Expand Down Expand Up @@ -128,9 +134,18 @@ jobs:
name: Build in RBC mode
runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
compiler: [gnu-11, gnu-12, gnu-13]

steps:
- uses: actions/checkout@v3

- uses: ./.github/actions/setup-compilers
with:
compiler: ${{ matrix.compiler }}

- uses: ./.github/actions/install-hemelb-deps
with:
name: rbc
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/py-hemetools.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
runs-on: ubuntu-22.04

strategy:
fail-fast: false
matrix:
python-version:
- '3.8'
Expand Down
8 changes: 6 additions & 2 deletions Code/util/ct_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <cstddef>
#include <string>
#include <string_view>
#include <type_traits>

namespace hemelb {
Expand All @@ -33,6 +34,9 @@ namespace hemelb {
constexpr std::string str() const {
return {str_, N};
}
constexpr std::string_view view() const {
return {str_, N};
}

constexpr char const *c_str() const {
return str_;
Expand All @@ -45,12 +49,12 @@ namespace hemelb {

template <std::size_t M, std::size_t N>
constexpr auto operator==(const ct_string<M>& left, const ct_string<N>& right) {
return left.str() == right.str();
return left.view() == right.view();
}

template <std::size_t N>
constexpr auto operator==(const ct_string<N>& left, const char* right) {
return left.str() == std::string{right};
return left.view() == std::string_view{right};
}
template <std::size_t N>
constexpr auto operator==(const char* left, const ct_string<N> right) {
Expand Down
Loading