Skip to content

Commit 17f69fd

Browse files
committed
Add test for function templates
1 parent 0d92eae commit 17f69fd

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

tests/CSharp/CSharp.Tests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,4 +1900,12 @@ public bool TestClassGenerateNativeToManaged(Type type)
19001900
{
19011901
return type.GetMethods(BindingFlags.NonPublic | BindingFlags.Static).Any(x => x.Name.Contains("NativeToManaged"));
19021902
}
1903+
1904+
[Test]
1905+
public void TestFunctionTemplate()
1906+
{
1907+
Assert.That(CSharpTemplates.FunctionTemplate(5.0), Is.EqualTo(5 + 4.2));
1908+
Assert.That(CSharpTemplates.FunctionTemplate(6f), Is.EqualTo(6 + 4.1f));
1909+
Assert.That(CSharpTemplates.FunctionTemplate(7), Is.EqualTo(7 + 4));
1910+
}
19031911
}

tests/CSharp/CSharpTemplates.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -945,6 +945,22 @@ class DLL_API FloatArrayF
945945
};
946946
const FloatArrayF<6> I6{ 1., 1., 1., 0., 0., 0. };
947947

948+
template <typename T>
949+
DLL_API inline T FunctionTemplate(T value) {
950+
if (std::is_same<T, double>::value)
951+
return 4.2 + value;
952+
else if (std::is_same<T, float>::value)
953+
return 4.1 + value;
954+
return 4 + value;
955+
}
956+
957+
inline void FunctionTemplateInstantiation()
958+
{
959+
FunctionTemplate<double>({});
960+
FunctionTemplate<float>({});
961+
FunctionTemplate<int>({});
962+
}
963+
948964
// KEEP ORDER OTHERWISE TEST WONT WORK
949965
namespace IncompleteClassTemplatesTests
950966
{
@@ -962,4 +978,4 @@ namespace IncompleteClassTemplatesTests
962978
{
963979
StructT<StructSizeT<4000>> st;
964980
};
965-
}
981+
}

0 commit comments

Comments
 (0)