Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6710391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:01:01+00:00 2026-05-26T08:01:01+00:00

I’ve got the following simple lambda: auto end_current_token = [&] { if (current !=

  • 0

I’ve got the following simple lambda:

auto end_current_token = [&] {
    if (current != Token()) {
        tokens.push_back(current);
        current = Token();
        cp = Codepoint();
    }
};

where current is of type Token and the operator is provided. But the compiler gives a strange error:

1>Lexer.cpp(6): error C2273: 'function-style cast' : illegal as right side of '->' operator

What’s the problem with this?

Edit: Much as I wish to say that this isn’t all the relevant code, it is. There’s not one single use of -> in the whole program, except implicitly on this, and the error message points clearly to the lambda posted. However, since it is so small, I will post all the code.

#include <fstream>
#include <string>
#include <iostream>
#include <vector>
namespace Wide {
    class Lexer {
        struct Codepoint {
            Codepoint() {
                column = 0;
                line = 0;
                cp = 0;
            }
            int column;
            int line;
            wchar_t cp;
            bool operator==(wchar_t other) {
                return cp == other;
            }
        };
        enum TokenType {
            IDENTIFIER,
        };
        struct Token {
            Token()
                : line(0)
                , columnbegin(0)
                , columnend(0) {}
            Token(const Codepoint& cp) {
                *this = cp;
            }
            bool operator!=(const Token& other) {
                return !(line == other.line && columnbegin == other.columnbegin && columnend == other.columnend);
            }
            Token& operator+=(const Codepoint& cp) {
                if (cp.column >= columnend)
                    columnend = cp.column;
                if (columnbegin == 0)
                    columnbegin = cp.column;
                Codepoints += cp.cp;
                if (line == 0)
                    line = cp.line;
            }
            Token& operator=(const Codepoint& cp) {
                line = cp.line;
                columnbegin = cp.column;
                columnend = cp.column;
                Codepoints = cp.cp;
            }

            int line;
            int columnbegin;
            int columnend;
            TokenType type;
            std::wstring Codepoints;
        };
        struct FileStreamer {
            int current;
            std::vector<Codepoint> codepoints;
            int line;
            int column;
            std::wifstream file;
            FileStreamer(std::wstring filename)
            : file(filename, std::ios::in | std::ios::binary) {
                line = 0;
                column = 0;
                current = 0;
                // Extract all the codepoints immediately.
                Codepoint cp;
                while(*this >> cp)
                    codepoints.push_back(cp);
            }
            operator bool() {
                return current != codepoints.size();
            }
            FileStreamer& operator>>(Codepoint& cp) {
                if (*this) {
                    cp = codepoints[current];
                    current++;
                }
                return *this;
            }
            void putback() {
                if (current > 0)
                    current--;
            }
        };
        std::vector<Token> tokens;
        FileStreamer stream;
    public:
        Lexer(std::wstring file)
            : stream(file) {}
        void operator()();
    };
}

Implementation:

void Wide::Lexer::operator()() {
    Codepoint cp;
    Token current;
    auto end_current_token = [&] {
        if (current != Token()) {
            tokens.push_back(current);
            current = Token();
            cp = Codepoint();
        }
    };
    auto check = [&](wchar_t codepoint) -> bool {
        if (cp == codepoint) {
            end_current_token();
            tokens.push_back(cp);
            return true;
        }
        return true;
    };
    auto is_whitespace = [&](wchar_t codepoint) {
        return codepoint == L' ' || codepoint == L'\n' || codepoint == L'\t';
    };
    auto is_newline = [&](wchar_t codepoint) {
        return codepoint == L'\n';
    };
    while(stream >> cp) {
        // check for whitespace or comment first
        if (is_whitespace(cp.cp)) {
            end_current_token();
            continue;
        }

        if (cp == L'/') {
            end_current_token();
            Codepoint backup = cp;
            stream >> cp; // no need to check the stream for failure
            if (cp == L'/') {
                while(stream >> cp && !is_newline(cp.cp));
                continue;
            }
            // didn't find comment.
            tokens.push_back(backup);
            // put the other codepoint back
            stream.putback();
            continue;
        }
        if (check(L'.')) continue;
        if (check(L',')) continue;
        if (check(L'-')) continue;
        if (check(L';')) continue;
        if (check(L'*')) continue;
        if (check(L'&')) continue;
        if (check(L'^')) continue;
        if (check(L'%')) continue;
        if (check(L'"')) continue;
        if (check(L'!')) continue;
        if (check(L':')) continue;
        if (check(L'~')) continue;
        if (check(L'/')) continue;
        if (check(L'>')) continue;
        if (check(L'<')) continue;
        if (check(L'|')) continue;
        if (check(L')')) continue;
        if (check(L'(')) continue;
        if (check(L'[')) continue;
        if (check(L']')) continue;
        if (check(L'}')) continue;
        if (check(L'{')) continue;
        // Identifier/keyword

        current += cp;
    }
}
int main() {
    Wide::Lexer Input(L"Input.txt");
}

Barring pipework like a couple includes, that’s it. That’s the whole program.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:01:01+00:00Added an answer on May 26, 2026 at 8:01 am

    I do not know why the compiler is complaining about operator->, but I’m thinking it’s either a compiler bug or Token is defined elsewhere. Maybe the assignment is somehow being rearranged as a call through a function pointer.

    In any case, I was able to get the code to compile by using explicit namespace scope resolution qualifiers. Try this:

    auto end_current_token = [&] {
            using namespace Wide;
        if (current != Wide::Lexer::Token()) {
            tokens.push_back(current);
            current = Wide::Lexer::Token();
            cp = Wide::Lexer::Codepoint();
        }
    };
    

    I believe — but I’m not positive — that this explicit resolution is needed anyway in the context of a lambda.

    I’ll do a little more research as to why you were having this problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm making a simple page using Google Maps API 3. My first. One marker
i got an object with contents of html markup in it, for example: string
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.