jeff-hykin / better-cpp-syntax

💾 The source of VS Code's C++ syntax highlighting
GNU General Public License v3.0
155 stars 30 forks source link

template template parameter does not colorized correctly #571

Closed soroshsabz closed 2 years ago

soroshsabz commented 3 years ago

ITNOA

where is "C_Cpp.enhancedColorization": "Disabled" ? ---> I don't find place of this configuration.

The code with a problem is:

Describe the bug

I have single file that name is main.cpp

and having something code


template <template <typename> class List, typename I>
void foo(std::function<I(I), const List<I>& list);

the problem is template inside of template is not colorized.

Expected behavior

I except internal template make colorized like external template keyword.

Code sample and logs

#include <cstdlib>
#include <cstddef>
#include <cmath>

#include <iostream>
#include <thread>
#include <functional>
#include <new>
#include <algorithm>
#include <iterator>
#include <chrono>
#include <vector>
#include <random>
#include <ranges>

using namespace std;

#ifdef __cpp_lib_hardware_interference_size
    using std::hardware_destructive_interference_size;
#else
    constexpr std::size_t hardware_destructive_interference_size = 2 * alignof(std::max_align_t);
#endif

struct NativeInt
{
    int value;
};
static_assert(alignof(NativeInt) < hardware_destructive_interference_size);

struct CacheInt
{
    alignas(hardware_destructive_interference_size) int value;
};
static_assert(alignof(CacheInt) >= hardware_destructive_interference_size);

void hello_world() noexcept
{
    cout << "salam" << endl;
}

template <typename T>
T my_sqrt(T value)
{
    return std::sqrt(value);
}

template <template <class I> class List, typename I, typename ElementType>
auto sqrt_function(std::function<I(I)> sqrt_func, const List<I>& elements) -> std::vector<ElementType>
{
    std::vector<ElementType> results;
    std::transform(elements.cbegin(), elements.cend(), std::back_inserter(results), sqrt_func);

    return results;
}

std::mutex global_mutex;

void change_data(std::vector<int>& data)
{
    std::lock_guard<std::mutex> lock{global_mutex};
    const unsigned int seed = std::chrono::system_clock::now().time_since_epoch().count();    
    std::ranges::shuffle(data, std::default_random_engine(seed));
}

int main()
{
    std::thread my_thread(hello_world);

    std::vector<int> data(30);
    std::iota(data.begin(), data.end(), 0);
    std::thread et1(change_data, std::ref(data));
    std::thread et2(change_data, std::ref(data));

    et1.join();
    et2.join();
    cout << "result of working parrallel on data: " << endl;

    std::copy(data.cbegin(), data.cend(), std::ostream_iterator<double>(std::cout, ", "));
    std::cout << std::endl;

    cout << "hardware concurrency: " << std::thread::hardware_concurrency() << endl;
    cout << "native int alignment: " << alignof(NativeInt) << endl;
    cout << "cache int alignement: " << alignof(CacheInt) << endl;
    cout << std::boolalpha << std::hash<std::thread::id>{}(my_thread.get_id()) << endl;

    my_thread.join();

    std::vector<double> results = sqrt_function<std::vector, float, double>(my_sqrt<float>, std::vector<float>(10, 9.f));
    std::copy(results.cbegin(), results.cend(), std::ostream_iterator<double>(std::cout, ", "));

    return EXIT_SUCCESS;
}
{
    "configurations": [
        {
            "name": "Linux",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [],
            "compilerPath": "/usr/bin/g++-11",
            "cStandard": "gnu17",
            "cppStandard": "gnu++20",
            "intelliSenseMode": "linux-gcc-x64"
        }
    ],
    "version": 4
}

Screenshots

image

soroshsabz commented 3 years ago

related to https://github.com/microsoft/vscode-cpptools/issues/8238

soroshsabz commented 3 years ago

related to #246

jeff-hykin commented 2 years ago

I believe this is fixed now

Screen Shot 2022-10-06 at 9 55 40 AM