{"id":4353,"date":"2022-06-23T08:08:49","date_gmt":"2022-06-23T06:08:49","guid":{"rendered":"https:\/\/store.algosyntax.com\/?post_type=asx-lms-tutorial-cpt&#038;p=4353"},"modified":"2026-03-09T05:09:53","modified_gmt":"2026-03-09T03:09:53","slug":"ue5-creating-predicates-for-tarray-tmap-and-tsets","status":"publish","type":"asx-lms-tutorial-cpt","link":"https:\/\/store.algosyntax.com\/tutorials\/unreal-engine\/ue5-creating-predicates-for-tarray-tmap-and-tsets\/","title":{"rendered":"UE5 Creating Predicates for TArray, TMap And TSets"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"4353\" class=\"elementor elementor-4353\" data-elementor-post-type=\"asx-lms-tutorial-cpt\">\n\t\t\t\t<div class=\"elementor-element elementor-element-de8dc83 e-flex e-con-boxed e-con e-parent\" data-id=\"de8dc83\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-5a54d76 elementor-widget elementor-widget-text-editor\" data-id=\"5a54d76\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>While trying to sort a TArray in unreal engine you may come across a requirement to define a\u00a0 PREDICATE_CLASS&amp; Predicate. In this tutorial, we will explain this type and how to define your own. You will mostly encounter this while working in C++ with algorithms that deal with unreal engine containers like TArray and TMap.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-5616787 elementor-widget elementor-widget-text-editor\" data-id=\"5616787\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<ol><li><h2>What are Predicates In Unreal Engine<\/h2><\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-bbfd5d6 elementor-widget elementor-widget-text-editor\" data-id=\"bbfd5d6\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>A Predicate in Unreal Engine C++ API is a function that returns a bool that takes two objects of the same class and compares them.<\/p><p>\u00a0<\/p><p>How you compare the objects is up to you, you just need to return a bool when you are done. These type of functions will help unreal engine sort your TArray based on anything you would like.<\/p><p>\u00a0<\/p><p>For example you may wish to sort Actors by Mesh Size, their speed or any variable.\u00a0 If you have dealt with overriding comparison operators in C++ , then you&#8217;ll be very glad to know Predicates are very similar to that.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-b79050b elementor-widget elementor-widget-text-editor\" data-id=\"b79050b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<ol start=2>\n \t<li>\n<h2>Common Functions That Require Predicates<\/h2>\n<\/li>\n<\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-65b386d elementor-widget elementor-widget-text-editor\" data-id=\"65b386d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>As mentioned in the intro, you may encounter Predicates when dealing with container algorithms like\u00a0<\/p><ul><li><a href=\"https:\/\/docs.unrealengine.com\/4.26\/en-US\/API\/Runtime\/Core\/Containers\/TArray\/FindByPredicate\/2\/\" target=\"_blank\" rel=\"noopener\">FindByPredicate<\/a><\/li><li><a href=\"https:\/\/docs.unrealengine.com\/4.26\/en-US\/API\/Runtime\/Core\/Containers\/TArray\/ContainsByPredicate\/index.html\" target=\"_blank\" rel=\"noopener\">ContainsByPredicate<\/a><\/li><li><a href=\"https:\/\/docs.unrealengine.com\/4.26\/en-US\/API\/Runtime\/Core\/Containers\/TArray\/Sort\/2\/index.html\" target=\"_blank\" rel=\"noopener\">Sort<\/a><\/li><li><a href=\"https:\/\/docs.unrealengine.com\/4.26\/en-US\/API\/Runtime\/Core\/Containers\/TArray\/RemoveAll\/index.html\" target=\"_blank\" rel=\"noopener\">RemoveAllByPredicate<\/a><\/li><li>..etc<\/li><\/ul><p>And a few more like that and they all require something like <br \/>( const PREDICATE_CLASS&amp; Predicate)\u00a0<br \/>as an argument.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-9b223af elementor-widget elementor-widget-template\" data-id=\"9b223af\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"template.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-template\">\n\t\t\t\t\t<div data-elementor-type=\"container\" data-elementor-id=\"7690\" class=\"elementor elementor-7690\" data-elementor-post-type=\"elementor_library\">\n\t\t\t\t<div class=\"elementor-element elementor-element-6ad81fd1 e-flex e-con-boxed e-con e-parent\" data-id=\"6ad81fd1\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t<div class=\"elementor-element elementor-element-239d8fe e-con-full e-flex e-con e-child\" data-id=\"239d8fe\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-355ee579 elementor-widget elementor-widget-heading\" data-id=\"355ee579\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<p class=\"elementor-heading-title elementor-size-default\">Nifty UE5 Plugin<\/p>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-249647d6 elementor-widget elementor-widget-image\" data-id=\"249647d6\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"image.default\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<a href=\"https:\/\/www.unrealengine.com\/marketplace\/en-US\/product\/umg-cinematics\" target=\"_blank\" rel=\"noopener\">\n\t\t\t\t\t\t\t<img fetchpriority=\"high\" decoding=\"async\" width=\"600\" height=\"600\" src=\"https:\/\/store.algosyntax.com\/wp-content\/uploads\/marketplace\/unreal-engine\/umg-cinematics.jpg\" class=\"attachment-full size-full wp-image-6160\" alt=\"UE5 Add Widgets To Sequencer\" \/>\t\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-738623d8 elementor-countdown--label-block elementor-widget elementor-widget-countdown\" data-id=\"738623d8\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"countdown.default\">\n\t\t\t\t\t\t\t<div data-evergreen-interval=\"169140\" data-expire-actions=\"[{&quot;type&quot;:&quot;hide&quot;}]\" class=\"elementor-countdown-wrapper\" data-date=\"\">\n\t\t\t<div class=\"elementor-countdown-item\"><span class=\"elementor-countdown-digits elementor-countdown-days\"><\/span> <span class=\"elementor-countdown-label\">Days<\/span><\/div><div class=\"elementor-countdown-item\"><span class=\"elementor-countdown-digits elementor-countdown-hours\"><\/span> <span class=\"elementor-countdown-label\">Hours<\/span><\/div><div class=\"elementor-countdown-item\"><span class=\"elementor-countdown-digits elementor-countdown-minutes\"><\/span> <span class=\"elementor-countdown-label\">Minutes<\/span><\/div><div class=\"elementor-countdown-item\"><span class=\"elementor-countdown-digits elementor-countdown-seconds\"><\/span> <span class=\"elementor-countdown-label\">Seconds<\/span><\/div>\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-6d6b97ac e-con-full e-flex e-con e-child\" data-id=\"6d6b97ac\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-fe1354 elementor-widget elementor-widget-heading\" data-id=\"fe1354\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<p class=\"elementor-heading-title elementor-size-default\">Add UMG Widgets To Level Sequences!<\/p>\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-2a5a679d e-con-full e-flex e-con e-child\" data-id=\"2a5a679d\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-63ca34df elementor-widget__width-auto elementor-widget elementor-widget-heading\" data-id=\"63ca34df\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<p class=\"elementor-heading-title elementor-size-default\"><a href=\"https:\/\/www.unrealengine.com\/marketplace\/en-US\/product\/umg-cinematics\" target=\"_blank\" rel=\"noopener\">&lt;b<strong><s><\/s> $49!<\/strong><\/a><\/p>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-fb95260 elementor-widget elementor-widget-button\" data-id=\"fb95260\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"button.default\">\n\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-button elementor-button-link elementor-size-sm\" href=\"https:\/\/www.unrealengine.com\/marketplace\/en-US\/product\/umg-cinematics\" target=\"_blank\" rel=\"noopener\">\n\t\t\t\t\t\t<span class=\"elementor-button-content-wrapper\">\n\t\t\t\t\t\t\t\t\t<span class=\"elementor-button-text\">Get UMG Cinematics<\/span>\n\t\t\t\t\t<\/span>\n\t\t\t\t\t<\/a>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-280fb1ff elementor-widget elementor-widget-text-editor\" data-id=\"280fb1ff\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>Did you Know?<\/p><p>You can add UMG Widgets to Sequencer for runtime text and shape layers. Suitable for QTE!<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c4ed9a2 elementor-widget elementor-widget-text-editor\" data-id=\"c4ed9a2\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<ol start=\"3\">\n \t<li>\n<h2>Creating Predicates In UE5 C++<\/h2>\n<\/li>\n<\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1c81cf7 elementor-widget elementor-widget-text-editor\" data-id=\"1c81cf7\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>Now that we have covered what they are, We will cover how to create them.<\/p><p>There are two main ways to define predicates. You can either use <a href=\"https:\/\/docs.microsoft.com\/en-us\/cpp\/cpp\/lambda-expressions-in-cpp?view=msvc-170\" target=\"_blank\" rel=\"noopener\">Lambdas<\/a> or define a static function in the class of the objects.<\/p><p>The function\/lambda IS the predicate and that&#8217;s what the functions like Sort() are asking you for.<\/p><p>They are asking you to submit a function that they will use to compare 2 objects that sit in the array. This function will get called multiple times by the Sort() function as it tries to determine what comes first.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-535a3f1 e-con-full e-flex e-con e-child\" data-id=\"535a3f1\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-698eb2c elementor-widget elementor-widget-heading\" data-id=\"698eb2c\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Creating &amp; Using Static Function Predicates<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a679512 elementor-widget elementor-widget-text-editor\" data-id=\"a679512\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>Creating your predicates as static functions in your class allows you to reuse them many times in any part of your project. It&#8217;s a write-once approach.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-69fe534 elementor-widget elementor-widget-text-editor\" data-id=\"69fe534\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<ol type=\"A\"><li><h4>Create the static member function<\/h4><\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-561b1d3 elementor-widget elementor-widget-text-editor\" data-id=\"561b1d3\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>The following points are important.<\/p><p>Go to your class and create a <strong>static\u00a0<\/strong>function that will take two objects from that very class. You can either pass them <strong>BY REFERENCE\u00a0<\/strong>or as Pointers. We will explain when to use which after the following code example.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-da853bc elementor-widget elementor-widget-code-highlight\" data-id=\"da853bc\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>class UApples\r\n{\r\n    double Size;\r\n    ...\r\n    \r\n    static bool CompareAscending(const UApples& AppleA, const UApples& AppleB)\r\n\t{\r\n\t\treturn AppleA.Size < AppleA.Size;\r\n\t}\r\n\t\r\n}<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-14be353 elementor-widget elementor-widget-text-editor\" data-id=\"14be353\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>In this example we are passing them in by reference because the TArray::Sort() function REQUIRES your predicate to take in references even if your TArray is made up of pointers.<\/p><p>So TArray&lt;UApples*&gt; will still require a predicate using UApples&amp;&#8230;<\/p><p><br \/>If you want to use Pointers you will need to call Algo::Sort&#8230; That&#8217;s a topic for another day.<\/p><p>Don&#8217;t forget to make your function static.<\/p><p>We&#8217;ve just created our predicate, now let&#8217;s see how to use it.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-de24a82 elementor-widget elementor-widget-text-editor\" data-id=\"de24a82\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<ol type=\"A\" start=\"2\">\n \t<li>\n<h4>Use The Static Function As A Predicate<\/h4>\n<\/li>\n<\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-159c63b elementor-widget elementor-widget-text-editor\" data-id=\"159c63b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>The following code is an example of a predicate (static function) in use, in the sort function. Notice how we don&#8217;t include function arguments or brackets. Just submitting the function&#8217;s name;<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-38d929e elementor-widget elementor-widget-code-highlight\" data-id=\"38d929e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>TArray<UApples*> Apples;\n\nApples.Sort(UApples::CompareAscending);<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t<div class=\"elementor-element elementor-element-796018a e-con-full e-flex e-con e-child\" data-id=\"796018a\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t<div class=\"elementor-element elementor-element-1a8ee43 elementor-widget elementor-widget-heading\" data-id=\"1a8ee43\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h3 class=\"elementor-heading-title elementor-size-default\">Lambda functions vs Static Functions<\/h3>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-a65bcd8 elementor-widget elementor-widget-text-editor\" data-id=\"a65bcd8\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>You can either use static functions or lambda functions. The BEST way to do it is to use both. Let&#8217;s look at the pros and cons of each and why you should use both.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-567f95d elementor-widget elementor-widget-heading\" data-id=\"567f95d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h4 class=\"elementor-heading-title elementor-size-default\">Static Functions Pros &amp; Cons<\/h4>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-bcaf0c9 elementor-widget elementor-widget-text-editor\" data-id=\"bcaf0c9\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>The main advantage of using static functions is that they are reusable. It&#8217;s a write-once, call-many-times approach, unlike Lamdas.<\/p><p>\u00a0<\/p><p>The disadvantage is they create an ambiguous problem when you overload the predicate. Consider the following function definitions for a better understanding:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-30e601b elementor-widget elementor-widget-code-highlight\" data-id=\"30e601b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>static bool IsBigger(AActor* inA,AActor* inB);\n\nstatic bool IsBigger(TWeakObj<AActor> inA,TWeakObj<AActor> inB)<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-1751cb3 elementor-widget elementor-widget-text-editor\" data-id=\"1751cb3\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>When submitting <strong>IsBigger\u00a0<\/strong>as the Predicate the compiler will complain and building will fail with a message along the lines of:<\/p><p>\u00a0<\/p><p>&#8220;the function IsBigger is <strong>Ambiguous<\/strong>&#8221; ,<\/p><p>\u00a0<\/p><p>meaning, it does not know which one between the two functions to use.<br \/>Let&#8217;s look at Lambda functions below as they will help us solve this problem.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-70349aa elementor-widget elementor-widget-heading\" data-id=\"70349aa\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h4 class=\"elementor-heading-title elementor-size-default\">Lambdas Pros &amp; Cons<\/h4>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-c77dbf4 elementor-widget elementor-widget-text-editor\" data-id=\"c77dbf4\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>The main <strong>advantage<\/strong> of using Lambdas is they resolve the problem of function ambiguity described as a disadvantage of using static functions above as lambdas don&#8217;t have names.<\/p><p>\u00a0<\/p><p>\u00a0<\/p><p>The <strong>disadvantage<\/strong> of using lambdas alone is that they are not reusable. You must rewrite the lambda or copy-paste the function algorithms each time you want to use it. This is error-prone and repetitive.<\/p><p>\u00a0<\/p><p>But , there is a solution, let&#8217;s look at the code solution to both problems below:<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-76e0498 elementor-widget elementor-widget-heading\" data-id=\"76e0498\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t\t<h4 class=\"elementor-heading-title elementor-size-default\">Using Lambdas with Static Functions<\/h4>\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-87edaf6 elementor-widget elementor-widget-code-highlight\" data-id=\"87edaf6\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"code-highlight.default\">\n\t\t\t\t\t\t\t<div class=\"prismjs-default copy-to-clipboard \">\n\t\t\t<pre data-line=\"\" class=\"highlight-height language-cpp line-numbers\">\n\t\t\t\t<code readonly=\"true\" class=\"language-cpp\">\n\t\t\t\t\t<xmp>\/\/Lamda\nAlgo::Sort(SomeArray, [](AActor* inA,AActor* inB)\n{\n    \/\/call SomeClass's static function here.\n    return SomeClass::IsBigger(inA,inB)\n}\n);<\/xmp>\n\t\t\t\t<\/code>\n\t\t\t<\/pre>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-699f339 elementor-widget elementor-widget-text-editor\" data-id=\"699f339\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>We are going to solve both disadvantages of using static functions and lamdas by taking the following approach:<\/p><ol><li>Create a static function(predicate)<\/li><li>Submit Lamdas as predicates then call the static functions within the lambda body.<br \/><br \/><\/li><\/ol><p>This approach solves both problems, we get both the reusability of static functions and eliminate the ambiguity problem since within the lamda body we use function arguments to specify exactly which function to call. See the example below:<br \/><br \/><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<div class=\"elementor-element elementor-element-cf673a4 elementor-widget elementor-widget-text-editor\" data-id=\"cf673a4\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t\t\t\t\t\t<p>You will not get any compiler errors related to ambiguity here and you will also get to use reusable code as static functions for your predicates.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"featured_media":0,"template":"","asx-lms-tutorial-categories":[45,58],"asx-lms-tutorial-tags":[46],"class_list":["post-4353","asx-lms-tutorial-cpt","type-asx-lms-tutorial-cpt","status-publish","hentry","asx-lms-tutorial-categories-unreal-engine","asx-lms-tutorial-categories-unreal-c-api","asx-lms-tutorial-tags-cpp","entry"],"acf":[],"_links":{"self":[{"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/asx-lms-tutorial-cpt\/4353","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/asx-lms-tutorial-cpt"}],"about":[{"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/types\/asx-lms-tutorial-cpt"}],"version-history":[{"count":0,"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/asx-lms-tutorial-cpt\/4353\/revisions"}],"wp:attachment":[{"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/media?parent=4353"}],"wp:term":[{"taxonomy":"asx-lms-tutorial-categories","embeddable":true,"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/asx-lms-tutorial-categories?post=4353"},{"taxonomy":"asx-lms-tutorial-tags","embeddable":true,"href":"https:\/\/store.algosyntax.com\/asx-rest\/wp\/v2\/asx-lms-tutorial-tags?post=4353"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}