Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add handling for templated lambdas and lambda specifiers #4115

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

rrsettgast
Copy link
Contributor

@rrsettgast rrsettgast commented Oct 6, 2023

When formatting templated lambdas and/or lambdas with specifiers the formatting would be "incorrect" to my eyes. For instance:

namespace ns1
{
namespace ns2
{
namespace ns3
{
namespace ns4
{

  template< int BF_INDEX >
  constexpr static REAL_TYPE value( REAL_TYPE const & coord )
  {
    return executeSequence< numSupportPoints >( [&] <int ... a > () constexpr
        {
          return ( valueFactor< BF_INDEX, a >( coord ) * ... );
        } );
  }

}
}
}
}

would lead to:

namespace ns1
{
namespace ns2
{
namespace ns3
{
namespace ns4
{

template< int BF_INDEX >
constexpr static REAL_TYPE value( REAL_TYPE const & coord )
{
  return executeSequence< numSupportPoints >( [&] <int ... a > () constexpr
          {
            return ( valueFactor< BF_INDEX, a >( coord ) * ... );
          } );
}

}
}
}
}

which is the same error I tried to fix for execution contexts in:
#2716

The attempt is to recognize the template and specifiers as valid in the context of the lambda.
The result is this:

namespace ns1
{
namespace ns2
{
namespace ns3
{
namespace ns4
{

template< int BF_INDEX >
constexpr static REAL_TYPE value( REAL_TYPE const & coord )
{
  return executeSequence< numSupportPoints >( [&]< int ... a > () constexpr
  {
    return ( valueFactor< BF_INDEX, a >( coord ) * ... );
  } );
}

}
}
}
}

As of the initial writing, I couldn't figure how to "properly" account for the new items, so I hacked it in a bit. Please let me know if you have suggestions to account for the new items in a manner more in line with the rest of the code.

for instance, additional <> can exist inside of the outer <> and the hard coded manner in which I set the chunks will break.

@rrsettgast
Copy link
Contributor Author

OK. I made a less hacky solution. I think the regressions are actually an improvement?

@guy-maurel
Copy link
Contributor

please, provide a test data, expected data and a configuration file
I want to reproduce your work.
Thanks

@rrsettgast
Copy link
Contributor Author

Hi @guy-maurel Where should I put things? Make a new entry or use an existing test file? There seem to be a little scatter in the lambda tests.

# TODO: Reduce the number of options, leave only those that affect lambda.
# TODO: Add tests for nested lambdas.

30750  cpp/ben_021.cfg                                      cpp/lambda.cpp
30751  cpp/lambda1.cfg                                      cpp/lambda.cpp
30752  cpp/lambda2.cfg                                      cpp/lambda.cpp
30753  cpp/lambda3.cfg                                      cpp/lambda2.cpp
30754  cpp/indent_with_tabs-0.cfg                           cpp/bug_i_682.h
30755  common/empty.cfg                                     cpp/bug_i_938.h
30756  cpp/bug_1296-T.cfg                                   cpp/bug_1296.cpp
30757  cpp/Issue_3054.cfg                                   cpp/Issue_3054.cpp
30758  cpp/Issue_3054-2.cfg                                 cpp/Issue_3054-2.cpp
30759  cpp/lambda4.cfg                                      cpp/lambda2.cpp

30760  cpp/bug_1296-F.cfg                                   cpp/bug_1296.cpp
30761  cpp/out-668-F.cfg                                    cpp/out-668.cpp
30762  cpp/out-668-T.cfg                                    cpp/out-668.cpp
30763  cpp/Issue_2166.cfg                                   cpp/Issue_2166.cpp
30764  cpp/Issue_2591.cfg                                   cpp/Issue_2591.cpp
30765  cpp/sp_cpp_lambda_square_paren-i.cfg                 cpp/lambda.cpp
30766  cpp/sp_cpp_lambda_square_brace-i.cfg                 cpp/lambda.cpp
30767  cpp/sp_cpp_lambda_paren_brace-i.cfg                  cpp/lambda.cpp
30768  cpp/sp_cpp_lambda_fparen-i.cfg                       cpp/sp_cpp_lambda_fparen.cpp

30770  cpp/sp_cpp_lambda_square_paren-r.cfg                 cpp/lambda.cpp
30771  cpp/sp_cpp_lambda_square_paren-f.cfg                 cpp/lambda.cpp
30772  cpp/sp_cpp_lambda_square_brace-r.cfg                 cpp/lambda.cpp
30773  cpp/sp_cpp_lambda_square_brace-f.cfg                 cpp/lambda.cpp
30774  cpp/sp_cpp_lambda_paren_brace-r.cfg                  cpp/lambda.cpp
30775  cpp/sp_cpp_lambda_paren_brace-f.cfg                  cpp/lambda.cpp
30776  cpp/sp_cpp_lambda_fparen-r.cfg                       cpp/sp_cpp_lambda_fparen.cpp
30777  cpp/sp_cpp_lambda_fparen-f.cfg                       cpp/sp_cpp_lambda_fparen.cpp

30780  cpp/lambda_in_one_liner.cfg                          cpp/lambda_in_one_liner.cpp
30781  cpp/lambda_in_one_liner.cfg                          cpp/lambda_brace_list.cpp

0907  cpp/Issue_1813.cfg                                   cpp/Issue_1813.cpp
30908  cpp/Issue_1813.cfg                                   cpp/Issue_1813-2.cpp
30909  cpp/Issue_1813.cfg                                   cpp/Issue_1813-3.cpp

@guy-maurel
Copy link
Contributor

Where is not important.
Important is to have some test data to check your work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants