how do you make c++ code that functions like multiple branching exec pins in a blueprint macro?

To do something like this in c++:

is there any generic way? You can do function callbacks but how could that be generic? Or maybe the thing that you make a template is just like an if/else block, and then you just copy paste that and put specific functions in place for the returns?

Header in a function library:


#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "GlobalFunctions.generated.h"

DECLARE_DYNAMIC_DELEGATE(FConditionDelegate);



/**
 * 
 */
UCLASS()
class ANX_API UGlobalFunctions : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()
public:
	
	//Function to call as argument in Do While Special
	
	UFUNCTION(BlueprintCallable, Category= "Utilities")
	static void DoWhileSpecial(bool bNewCondition, bool& bCurrentCondition, bool& bHasChangedToTrueExecuted, bool& bHasChangedToFalseExecuted, 
							const FConditionDelegate& OnChangedToTrue, 
							const FConditionDelegate& OnChangedToFalse, 
							const FConditionDelegate& WhileTrue, 
							const FConditionDelegate& WhileFalse);
};


Implementation:

void UGlobalFunctions::DoWhileSpecial(bool bNewCondition, bool& bCurrentCondition, bool& bHasChangedToTrueExecuted, bool& bHasChangedToFalseExecuted,
										  const FConditionDelegate& OnChangedToTrue,
										  const FConditionDelegate& OnChangedToFalse,
										  const FConditionDelegate& WhileTrue,
										  const FConditionDelegate& WhileFalse)
{
	// If the condition is true
	if (bNewCondition)
	{
		// If this is the first time the condition is true
		if (!bCurrentCondition && !bHasChangedToTrueExecuted)
		{
			OnChangedToTrue.ExecuteIfBound();
			bHasChangedToTrueExecuted = true;
			bHasChangedToFalseExecuted = false;
		}

		// Execute the continuous "while true" delegate
		WhileTrue.ExecuteIfBound();
	}
	else
	{
		// If this is the first time the condition is false
		if (bCurrentCondition && !bHasChangedToFalseExecuted)
		{
			OnChangedToFalse.ExecuteIfBound();
			bHasChangedToFalseExecuted = true;
			bHasChangedToTrueExecuted = false;
		}

		// Execute the continuous "while false" delegate
		WhileFalse.ExecuteIfBound();
	}

	// Update the current condition
	bCurrentCondition = bNewCondition;
}

Blueprint result: