Skip to content

Commit

Permalink
Merge branch 'main' into feat--add-concept-exercise-for-auto-and-smar…
Browse files Browse the repository at this point in the history
…t-pointers
  • Loading branch information
vaeng authored Jan 23, 2025
2 parents 322c0fb + 3ffe4b7 commit a526e01
Show file tree
Hide file tree
Showing 234 changed files with 57,158 additions and 916 deletions.
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'daily'
interval: 'monthly'
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
matrix:
compiler: [clang++-6.0, g++-10]
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Install Dependencies
# Boost must be installed only because the CMake version (3.12) can't
# detect the installed Boost version (1.69)
Expand All @@ -37,7 +37,7 @@ jobs:
matrix:
compiler: [clang++, g++]
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Install Dependencies
# Boost must be installed only because the CMake version (3.12) can't
# detect the installed Boost version (1.69)
Expand All @@ -64,7 +64,7 @@ jobs:
needs: [linux-min]
runs-on: windows-2022
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Run Tests
shell: powershell
# Delete the exercises that require Boost to avoid issues with Windows setup.
Expand All @@ -80,7 +80,7 @@ jobs:
needs: [linux-min]
runs-on: macOS-latest
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Install Boost
run: brew install boost
- name: Run Tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/hello-world.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
name: Hello World Fails
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- name: Check Hello World Fails
run: bin/check-hello-world.sh
env:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/no-important-files-changed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ permissions:
pull-requests: write

jobs:
pause:
check:
uses: exercism/github-actions/.github/workflows/check-no-important-files-changed.yml@main
with:
repository: ${{ github.event.pull_request.head.repo.owner.login }}/${{ github.event.pull_request.head.repo.name }}
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/ping-cross-track-maintainers-team.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Ping cross-track maintainers team

on:
pull_request_target:
types:
- opened

permissions:
pull-requests: write

jobs:
ping:
if: github.repository_owner == 'exercism' # Stops this job from running on forks
uses: exercism/github-actions/.github/workflows/ping-cross-track-maintainers-team.yml@main
secrets:
github_membership_token: ${{ secrets.COMMUNITY_CONTRIBUTIONS_WORKFLOW_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/verify-code-formatting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
runs-on: [ubuntu-22.04]
steps:
- name: "Checkout code"
uses: actions/checkout@9bb56186c3b09b4f86b1c65136769dd318469633
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683

- name: "Verify formatting of all files"
if: github.ref == 'refs/heads/master'
Expand Down
33 changes: 18 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
cmake_minimum_required(VERSION 3.5.1)
project(exercism CXX)

set(alt_exercise_tree ${CMAKE_CURRENT_SOURCE_DIR}/build_exercises/practice)

function(build_fixup exercise_dir alt_exercise_root)
function(build_fixup exercise_dir alt_exercise_root exercise_type example_name)
string(REPLACE "-" "_" file ${exercise_dir})
set(source ${CMAKE_CURRENT_SOURCE_DIR}/exercises/practice/${exercise_dir})
set(source ${CMAKE_CURRENT_SOURCE_DIR}/exercises/${exercise_type}/${exercise_dir})
if(EXISTS ${source})
set(alt_exercise_dir ${alt_exercise_root}/${exercise_dir})
file(COPY ${source} DESTINATION ${alt_exercise_root})
if(EXISTS ${alt_exercise_dir}/.meta/example.h)
file(RENAME ${alt_exercise_dir}/.meta/example.h ${alt_exercise_dir}/${file}.h)
if(EXISTS ${alt_exercise_dir}/.meta/${example_name}.h)
file(RENAME ${alt_exercise_dir}/.meta/${example_name}.h ${alt_exercise_dir}/${file}.h)
endif()
if(EXISTS ${alt_exercise_dir}/.meta/example.cpp)
file(RENAME ${alt_exercise_dir}/.meta/example.cpp ${alt_exercise_dir}/${file}.cpp)
if(EXISTS ${alt_exercise_dir}/.meta/${example_name}.cpp)
file(RENAME ${alt_exercise_dir}/.meta/${example_name}.cpp ${alt_exercise_dir}/${file}.cpp)
endif()
endif()
endfunction()

function(add_exercises exercise_type example_name)
file(GLOB exercise_list ${CMAKE_CURRENT_SOURCE_DIR}/exercises/${exercise_type}/*)
set(alt_exercise_tree ${CMAKE_CURRENT_SOURCE_DIR}/build_exercises/${exercise_type})
foreach(exercise_dir ${exercise_list})
get_filename_component(exercise ${exercise_dir} NAME)
build_fixup(${exercise} ${alt_exercise_tree} ${exercise_type} ${example_name})
add_subdirectory(${alt_exercise_tree}/${exercise})
endforeach()
endfunction()

option(EXERCISM_RUN_ALL_TESTS "Run all Exercism tests" On)
option(EXERCISM_COMMON_CATCH "Link against a common Catch2 main lib." On)

Expand All @@ -30,10 +38,5 @@ if(EXERCISM_COMMON_CATCH)
)
endif()

file(GLOB exercise_list ${CMAKE_CURRENT_SOURCE_DIR}/exercises/practice/*)

foreach(exercise_dir ${exercise_list})
get_filename_component(exercise ${exercise_dir} NAME)
build_fixup(${exercise} ${alt_exercise_tree})
add_subdirectory(${alt_exercise_tree}/${exercise})
endforeach()
add_exercises("concept" "exemplar")
add_exercises("practice" "example")
35 changes: 9 additions & 26 deletions bin/check-formatting.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
set -e

print_help() {
echo "This script verifies if one or more files are formatted using the provided"
Expand All @@ -13,8 +14,6 @@ print_help() {
echo " warnings are returned for each invalid path."
}

cd "$(dirname "$0")"

# Get files list
FILES=()
while [[ $# -gt 0 ]]
Expand All @@ -31,40 +30,24 @@ do
shift
done

# Verifies a single file is formatted following .clang-format style
run_check() {
local FILE="$1"
CHECK_RESULT=0
# Get diff between current content and formatted content
local OUTPUT=$(diff -u <(cat "$FILE") <(clang-format --style=file "$FILE"))
# Shows diff output only if files are different
if [[ $OUTPUT != "" ]]; then
echo "$OUTPUT"
CHECK_RESULT=1
fi
}

# Result of this script, incremented by one for each unformatted file
# Result of this script
RESULT=0
# List of warnings
WARNINGS=()

# Iterate files to run format check
for INDEX in "${!FILES[@]}"; do
FILE="${FILES[$INDEX]}"
if [[ -f "$FILE" ]]; then
run_check $FILE
RESULT=$(( RESULT + CHECK_RESULT ))
if ! clang-format --dry-run --Werror "$FILE"; then
RESULT=1
fi
elif [[ -d "$FILE" ]]; then
WARNINGS+=("Path is a directory: $FILE")
echo "Path is a directory: $FILE"
RESULT=1
else
WARNINGS+=("File not found: $FILE")
echo "File not found: $FILE"
RESULT=1
fi
done

for INDEX in "${!WARNINGS[@]}"; do
echo "${WARNINGS[$INDEX]}"
done

echo "Done"
exit $RESULT
23 changes: 12 additions & 11 deletions bin/fetch-configlet
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ get_download_url() {
local latest='https://api.github.com/repos/exercism/configlet/releases/latest'
local arch
case "$(uname -m)" in
x86_64) arch='x86-64' ;;
*686*) arch='i386' ;;
*386*) arch='i386' ;;
*) arch='x86-64' ;;
aarch64|arm64) arch='arm64' ;;
x86_64) arch='x86-64' ;;
*686*) arch='i386' ;;
*386*) arch='i386' ;;
*) arch='x86-64' ;;
esac
local suffix="${os}_${arch}.${ext}"
curl "${curlopts[@]}" --header 'Accept: application/vnd.github.v3+json' "${latest}" |
Expand All @@ -47,7 +48,7 @@ main() {
fi

local os
case "$(uname)" in
case "$(uname -s)" in
Darwin*) os='macos' ;;
Linux*) os='linux' ;;
Windows*) os='windows' ;;
Expand All @@ -58,8 +59,8 @@ main() {

local ext
case "${os}" in
windows*) ext='zip' ;;
*) ext='tar.gz' ;;
windows) ext='zip' ;;
*) ext='tar.gz' ;;
esac

echo "Fetching configlet..." >&2
Expand All @@ -69,16 +70,16 @@ main() {
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"

case "${ext}" in
*zip) unzip "${output_path}" -d "${output_dir}" ;;
*) tar xzf "${output_path}" -C "${output_dir}" ;;
zip) unzip "${output_path}" -d "${output_dir}" ;;
*) tar xzf "${output_path}" -C "${output_dir}" ;;
esac

rm -f "${output_path}"

local executable_ext
case "${os}" in
windows*) executable_ext='.exe' ;;
*) executable_ext='' ;;
windows) executable_ext='.exe' ;;
*) executable_ext='' ;;
esac

local configlet_path="${output_dir}/configlet${executable_ext}"
Expand Down
2 changes: 1 addition & 1 deletion concepts/functions/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Stubborn {
response = reply;
}
string answer(const string& question) const {
if (question.lenghth() == 0) { return "";}
if (question.length() == 0) { return "";}
return response;
}
private:
Expand Down
2 changes: 1 addition & 1 deletion concepts/functions/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class Stubborn {
response = reply;
}
string answer(const string& question) const {
if (question.lenghth() == 0) { return "";}
if (question.length() == 0) { return ""; }
return response;
}
private:
Expand Down
8 changes: 8 additions & 0 deletions concepts/literals/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"blurb": "C++ literals represent fixed values, including strings and different numeric formats.",
"authors": [
"vaeng"
],
"contributors": [
]
}
76 changes: 76 additions & 0 deletions concepts/literals/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# About

Literals are fixed values that are used directly in code.
They do not need any computation during run-time.
They come in various forms to represent different types of data efficiently.
The most frequent literals are of numeric nature, but there are also literal operators for date, time and string types.
A later concept will show how user-defined literal operators can be used.

## Numeric Literals

Numeric literals include decimal, octal, hexadecimal, and binary representations.
These basics were already covered in the [numbers concept][numbers-concept].

All representations like `23`, `0x50f7ba11` and `0xba5eba11` are understood as `int` by the compiler.
The general `int` type is signed and ([depending on the compiler and the system][in-depth-integers]), often has a range of `-2'147'483'648` to `2'147'483'647`.
This is sufficient most of the time and you don't need to worry about the specific type.

Some use-cases demand larger ranges or very small memory footprints of programs.
To be explicit one can directly state specific integer types with the numeric literal.

When negative numbers aren't needed, but the added range is desired the `u` or `U` suffix are used for _unsigned_ integers.
For greater ranges `L` or even `LL` can be used for long and long long types.

~~~~exercism/caution
The use of lower-case `l` is permitted, but it is easily confused with the number `1` and thus discouraged.
~~~~

```cpp
auto net_worth_christian_grey{2'500'000'000U}; // out of range for 32-bit integers
auto net_worth_carlisle_cullen{46'000'000'000LL}; // int and uint are not enough
```
Floating-point numbers usually resolve to `double` during compilation.
This is a good default case and use-cases with the narrower `float` type are less frequent than the unsigned example above.
```cpp
auto light_year_in_m{9.46073e+15f}; // well in the range of float
auto earth_to_edge_comoving_distance_in_nm{4.32355e+32}; // needs double type for magnitude
auto eulers_number{2.718281828459045}; // needs double type for precision
```

~~~~exercism/advanced
## Character and String Literals
Other concepts already used character literals with single quotes like `'}'` or `'@'`.
In C++ `char` is limited to the first 128 [ascii character codes][ascii-code].
To use several ascii chars or extended ascii characters like `‰` or even unicode characters like `麗` and `ẞ` other types are needed.
In previous concept string literals were introduced with _double quotes_: `"一体どういう意味ですか。C++です"`.
The actual type of this Japanese phrase is `const char (&)[46]`, a C-style string.
The use of string literals is not activated by default.
To use the _string_ literal `""s` or the _string-view_ literal `""sv`, the user has to specify their use by using the related namespace:
```cpp
#include <string>
#include <string_view>
using namespace std::literals;
auto green_light{"무궁화 꽃 이 피었 습니다"};
// green_light type is const char (&)[36]
auto umbrella{"달고나"s};
// umbrella type is std::basic_string<char>, the same as std::string
auto il_nam{"보는 것이 하는 것보다 더 재미있을 수가 없지"sv};
// il_nam type is std::basic_string_view<char>
```
A _string_view_ can be seen as a reference to a const string.
[ascii-code]: https://www.ascii-code.com/
~~~~

[numbers-concept]: https://exercism.org/tracks/cpp/concepts/numbers
[in-depth-integers]: https://www.learncpp.com/cpp-tutorial/fixed-width-integers-and-size-t/
Loading

0 comments on commit a526e01

Please sign in to comment.