brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · 58b7216 Raw
56 lines · plain
1// RUN: rm -rf %t2// RUN: mkdir -p %t3// RUN: split-file %s %t4//5// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/Cache.cppm -o %t/Cache.pcm6// RUN: %clang_cc1 -std=c++20 %t/Use.cpp -fmodule-file=Fibonacci.Cache=%t/Cache.pcm \7// RUN:     -fsyntax-only -verify8 9// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/Cache.cppm -o %t/Cache.pcm10// RUN: %clang_cc1 -std=c++20 %t/Use.cpp -fmodule-file=Fibonacci.Cache=%t/Cache.pcm \11// RUN:     -fsyntax-only -verify12 13//--- Cache.cppm14export module Fibonacci.Cache;15 16export namespace Fibonacci17{18	constexpr unsigned long Recursive(unsigned long n)19	{20		if (n == 0)21			return 0;22		if (n == 1)23			return 1;24		return Recursive(n - 2) + Recursive(n - 1);25	}26 27	template<unsigned long N>28	struct Number{};29 30	struct DefaultStrategy31	{32		constexpr unsigned long operator()(unsigned long n, auto... other) const33		{34			return (n + ... + other);35		}36	};37 38    constexpr unsigned long Compute(Number<10ul>, auto strategy)39	{40		return strategy(Recursive(10ul));41	}42 43	template<unsigned long N, typename Strategy = DefaultStrategy>44	constexpr unsigned long Cache = Compute(Number<N>{}, Strategy{});45 46    template constexpr unsigned long Cache<10ul>;47}48 49//--- Use.cpp50// expected-no-diagnostics51import Fibonacci.Cache;52 53constexpr bool value = Fibonacci::Cache<10ul> == 55;54 55static_assert(value == true, "");56