Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Show HN: Better Hub – A better GitHub experience

    Show HN: Better Hub – A better GitHub experience

    Show HN: Better Hub – A better GitHub experience

    Facebook X (Twitter) Instagram
    • Artificial Intelligence
    • Business Technology
    • Cryptocurrency
    • Gadgets
    • Gaming
    • Health
    • Software and Apps
    • Technology
    Facebook X (Twitter) Instagram Pinterest Vimeo
    Tech AI Verse
    • Home
    • Artificial Intelligence

      Tensions between the Pentagon and AI giant Anthropic reach a boiling point

      February 21, 2026

      Read the extended transcript: President Donald Trump interviewed by ‘NBC Nightly News’ anchor Tom Llamas

      February 6, 2026

      Stocks and bitcoin sink as investors dump software company shares

      February 4, 2026

      AI, crypto and Trump super PACs stash millions to spend on the midterms

      February 2, 2026

      To avoid accusations of AI cheating, college students are turning to AI

      January 29, 2026
    • Business

      How Smarsh built an AI front door for regulated industries — and drove 59% self-service adoption

      February 24, 2026

      Where MENA CIOs draw the line on AI sovereignty

      February 24, 2026

      Ex-President’s shift away from Xbox consoles to cloud gaming reportedly caused friction

      February 24, 2026

      Gartner: Why neoclouds are the future of GPU-as-a-Service

      February 21, 2026

      The HDD brand that brought you the 1.8-inch, 2.5-inch, and 3.5-inch hard drives is now back with a $19 pocket-sized personal cloud for your smartphones

      February 12, 2026
    • Crypto

      Crypto Market Rebound Wipes Out Nearly $500 Million in Short Positions

      February 26, 2026

      Ethereum Climbs Above $2000: Investors Step In With Fresh Accumulation

      February 26, 2026

      Mutuum Finance (MUTM) Prepares New Feature Expansion for V1 Protocol

      February 26, 2026

      Bitcoin Rebounds Toward $70,000, But Is It a Momentary Relief or Slow Bull Run Signal?

      February 26, 2026

      IMF: US Inflation Won’t Hit Fed Target Until 2027, Delaying Rate Cuts

      February 26, 2026
    • Technology

      Meet Expedition: Handheld, PCWorld’s new portable gaming show

      February 27, 2026

      Lenovo’s new folding handheld gaming tablet thing is ridiculous

      February 27, 2026

      Nvidia GPU shortages are here again

      February 27, 2026

      Nano Banana 2 has an ace up its sleeve

      February 27, 2026

      Baseus 100W USB-C cable for $8: Super-fast charging for your devices

      February 27, 2026
    • Others
      • Gadgets
      • Gaming
      • Health
      • Software and Apps
    Check BMI
    Tech AI Verse
    You are at:Home»Technology»Cppyy: Automatic Python-C++ Bindings
    Technology

    Cppyy: Automatic Python-C++ Bindings

    TechAiVerseBy TechAiVerseJuly 16, 2025No Comments3 Mins Read4 Views
    Facebook Twitter Pinterest Telegram LinkedIn Tumblr Email Reddit
    Share
    Facebook Twitter LinkedIn Pinterest WhatsApp Email

    Cppyy: Automatic Python-C++ Bindings

    cppyy is an automatic, run-time, Python-C++ bindings generator, for calling
    C++ from Python and Python from C++.
    Run-time generation enables detailed specialization for higher performance,
    lazy loading for reduced memory use in large scale projects, Python-side
    cross-inheritance and callbacks for working with C++ frameworks, run-time
    template instantiation, automatic object downcasting, exception mapping, and
    interactive exploration of C++ libraries.
    cppyy delivers this without any language extensions, intermediate languages,
    or the need for boiler-plate hand-written code.
    For design and performance, see this PyHPC’16 paper, albeit that the
    CPython/cppyy performance has been vastly improved since, as well as this
    CAAS presentation.
    For a quick teaser, see Jason Turner’s introduction video.

    cppyy is based on Cling, the C++ interpreter, to match Python’s dynamism,
    interactivity, and run-time behavior.
    Consider this session, showing dynamic, interactive, mixing of C++ and Python
    features (there are more examples throughout the documentation and in the
    tutorial):

    >>> import cppyy
    >>> cppyy.cppdef("""
    ... class MyClass {
    ... public:
    ...     MyClass(int i) : m_data(i) {}
    ...     virtual ~MyClass() {}
    ...     virtual int add_int(int i) { return m_data + i; }
    ...     int m_data;
    ... };""")
    True
    >>> from cppyy.gbl import MyClass
    >>> m = MyClass(42)
    >>> cppyy.cppdef("""
    ... void say_hello(MyClass* m) {
    ...     std::cout << "Hello, the number is: " << m->m_data << std::endl;
    ... }""")
    True
    >>> MyClass.say_hello = cppyy.gbl.say_hello
    >>> m.say_hello()
    Hello, the number is: 42
    >>> m.m_data = 13
    >>> m.say_hello()
    Hello, the number is: 13
    >>> class PyMyClass(MyClass):
    ...     def add_int(self, i):  # python side override (CPython only)
    ...         return self.m_data + 2*i
    ...
    >>> cppyy.cppdef("int callback(MyClass* m, int i) { return m->add_int(i); }")
    True
    >>> cppyy.gbl.callback(m, 2)             # calls C++ add_int
    15
    >>> cppyy.gbl.callback(PyMyClass(1), 2)  # calls Python-side override
    5
    >>>
    

    With a modern C++ compiler having its back, cppyy is future-proof.
    Consider the following session using boost::any, a capsule-type that
    allows for heterogeneous containers in C++.
    The Boost library is well known for its no holds barred use of modern C++
    and heavy use of templates:

    >>> import cppyy
    >>> cppyy.include('boost/any.hpp')       # assumes you have boost installed
    >>> from cppyy.gbl import std, boost
    >>> val = boost.any()                    # the capsule
    >>> val.__assign__(std.vector[int]())    # assign it a std::vector
    
    >>> val.type() == cppyy.typeid(std.vector[int])    # verify type
    True
    >>> extract = boost.any_cast[int](std.move(val))   # wrong cast
    Traceback (most recent call last):
      File "", line 1, in 
    cppyy.gbl.boost.bad_any_cast: Could not instantiate any_cast:
      int boost::any_cast(boost::any&& operand) =>
        wrapexcept: boost::bad_any_cast: failed conversion using boost::any_cast
    >>> extract = boost.any_cast[std.vector[int]](val) # correct cast
    >>> type(extract) is std.vector[int]
    True
    >>> extract += xrange(100)
    >>> len(extract)
    100
    >>> val.__assign__(std.move(extract))    # move forced
    
    >>> len(extract)                         # now empty (or invalid)
    0
    >>> extract = boost.any_cast[std.vector[int]](val)
    >>> list(extract)
    [0, 1, 2, 3, 4, 5, 6, ..., 97, 98, 99]
    >>>
    

    Of course, there is no reason to use Boost from Python (in fact, this example
    calls out for pythonizations), but it shows that
    cppyy seamlessly supports many advanced C++ features.

    cppyy is available for both CPython (v2 and v3) and PyPy, reaching
    C++-like performance with the latter.
    It makes judicious use of precompiled headers, dynamic loading, and lazy
    instantiation, to support C++ programs consisting of millions of lines of
    code and many thousands of classes.
    cppyy minimizes dependencies to allow its use in distributed, heterogeneous,
    development environments.

    Bugs and feedback

    Please report bugs or requests for improvement on the issue tracker.

    Share. Facebook Twitter Pinterest LinkedIn Reddit WhatsApp Telegram Email
    Previous ArticleGauntlet AI (YC S17): All expenses paid training in AI and $200k+job
    Next Article Finally, a dev kit for designing on-device, mobile AI apps is here: Liquid AI’s LEAP
    TechAiVerse
    • Website

    Jonathan is a tech enthusiast and the mind behind Tech AI Verse. With a passion for artificial intelligence, consumer tech, and emerging innovations, he deliver clear, insightful content to keep readers informed. From cutting-edge gadgets to AI advancements and cryptocurrency trends, Jonathan breaks down complex topics to make technology accessible to all.

    Related Posts

    Meet Expedition: Handheld, PCWorld’s new portable gaming show

    February 27, 2026

    Lenovo’s new folding handheld gaming tablet thing is ridiculous

    February 27, 2026

    Nvidia GPU shortages are here again

    February 27, 2026
    Leave A Reply Cancel Reply

    Top Posts

    Ping, You’ve Got Whale: AI detection system alerts ships of whales in their path

    April 22, 2025695 Views

    Lumo vs. Duck AI: Which AI is Better for Your Privacy?

    July 31, 2025279 Views

    6.7 Cummins Lifter Failure: What Years Are Affected (And Possible Fixes)

    April 14, 2025161 Views

    6 Best MagSafe Phone Grips (2025), Tested and Reviewed

    April 6, 2025122 Views
    Don't Miss
    Uncategorized February 27, 2026

    Show HN: Better Hub – A better GitHub experience

    Show HN: Better Hub – A better GitHub experienceChoose GitHub access before connectingClick any permission…

    Show HN: Better Hub – A better GitHub experience

    Show HN: Better Hub – A better GitHub experience

    Meet Expedition: Handheld, PCWorld’s new portable gaming show

    Stay In Touch
    • Facebook
    • Twitter
    • Pinterest
    • Instagram
    • YouTube
    • Vimeo

    Subscribe to Updates

    Get the latest creative news from SmartMag about art & design.

    About Us
    About Us

    Welcome to Tech AI Verse, your go-to destination for everything technology! We bring you the latest news, trends, and insights from the ever-evolving world of tech. Our coverage spans across global technology industry updates, artificial intelligence advancements, machine learning ethics, and automation innovations. Stay connected with us as we explore the limitless possibilities of technology!

    Facebook X (Twitter) Pinterest YouTube WhatsApp
    Our Picks

    Show HN: Better Hub – A better GitHub experience

    February 27, 20260 Views

    Show HN: Better Hub – A better GitHub experience

    February 27, 20260 Views

    Show HN: Better Hub – A better GitHub experience

    February 27, 20260 Views
    Most Popular

    7 Best Kids Bikes (2025): Mountain, Balance, Pedal, Coaster

    March 13, 20250 Views

    VTOMAN FlashSpeed 1500: Plenty Of Power For All Your Gear

    March 13, 20250 Views

    This new Roomba finally solves the big problem I have with robot vacuums

    March 13, 20250 Views
    © 2026 TechAiVerse. Designed by Divya Tech.
    • Home
    • About Us
    • Contact Us
    • Privacy Policy
    • Terms & Conditions

    Type above and press Enter to search. Press Esc to cancel.