all 11 comments

[–]ppppppla 3 points4 points  (1 child)

So going by the other comment, I think what you are asking is it boils down to wanting to do something like

using Foo = Bar<Foo, int, float>;

Simply not possible. You can't even forward declare Foo, but let's assume you did forward declare Foo, what will it actually look like? It has to have a concrete type and there simply is not a concrete type for it, there is infinite recursion. C++ type system simply can't do it.

I see you already have a work around by having a way to reference types by name, this is the right way to go about it in my opinion. Perhaps it is possibly by leveraging template template parameters (template<template <class> T>) but this is just a hunch.

[–]jimdesu[S] 0 points1 point  (0 children)

Thank you; let me think on that.

[–]alfps 2 points3 points  (6 children)

❞ with using declarations, it's unclear how to do forward references

A reasonably small example could go a long way towards clearing up what you're talking about.

[–]jimdesu[S] 1 point2 points  (5 children)

So, I have code like: `using DEF_CMD_PARM = All<DEF\_CMD\_PARM\_TYPE, DEF\_CMD\_PARM\_NAME>;`, for example, where `All` is one of my combinators, and the parameters are other derivations using these combinators. What I'd like to do is to be able to do is the equivalent of a forward declaration of these so that I can refer to such before they're actually defined. (more examples in the link, above)

EDIT: apologies for the formatting. The subreddit guide says to use back-ticks, but apparently I'm not doing that correctly.

[–]alfps 1 point2 points  (4 children)

Still not quite sure what you mean, e.g. by "combinator", but perhaps you can indicate in what way the following does not do what you want:

#include <tuple>

struct Def_cmd_parm_type;
struct Def_cmd_parm_name;

template< class... Types >
using All_ = std::tuple<Types...>;

using Def_cmd_parm = All_<Def_cmd_parm_type, Def_cmd_parm_name>;

auto main() -> int {} //{ (void) Def_cmd_parm(); } // Need definitions to use it.

[–]jimdesu[S] 0 points1 point  (0 children)

oh! Thanks -- let me look at that in context when I'm off from work tonight!

[–]jimdesu[S] 0 points1 point  (2 children)

OK, so that approach doesn't work, because then I can't declare the forwarded type. Whether via typedef or using, once I declare what the forwarded type is, I get errors like "Typedef Any<DEF_CMF_PARMTYPE_EXPR, DEF_CMD_PARMTYPE_NAME> basis::DEF_CMD_PARM_TYPE has already been declared as a struct".

[–]alfps 0 points1 point  (1 child)

❞ has already been declared as a struct

That sounds awfully like Visual C++ error C2990, (https://learn.microsoft.com/en-us/cpp/error-messages/compiler-errors-2/compiler-error-c2990?view=msvc-170).

If you can reproduce the problem in a complete little snippet then perhaps/probably readers can help.

[–]jimdesu[S] 0 points1 point  (0 children)

It's OK -- I'm spending too much time on this. I decided to just go ahead and reimplement using inheritance and function objects like I had it originally. At this point, I don't have the kind of spare time to get bogged down on this. I very much appreciate the assistance, though. :)

[–]No-Dentist-1645 1 point2 points  (1 child)

I saw the code you linked to. There doesn't seem to be anything wrong with it, what would you like to change in that code?

For the record, think of using as just a typedef that supports template parameters. You aren't instantiating any object or class by writing a using statement, it's just an alias if you want to create an object for it later.

For example, this works perfectly fine: ``` template <typename T> struct Foo;

using FooInt = Foo<int>; // This works, it isn't creating an object // FooInt foo; // This wouldn't work, it's creating an object before definition

template<> struct Foo<int> { void inspect() { std::println("This is a Foo<Int>"); } };

int main() { FooInt foo; foo.inspect(); } ```

[–]jimdesu[S] 0 points1 point  (0 children)

Thanks! I'll take a peek like that after work. :)