Changeset 1b6477e in mainline


Ignore:
Timestamp:
2018-07-05T21:41:17Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ef9d0988
Parents:
c2c1966
git-author:
Jaroslav Jindrak <dzejrou@…> (2017-10-11 16:29:33)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:17)
Message:

cpp: finished typeinfo and typeid support

Location:
uspace/lib/cpp
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/Makefile

    rc2c1966 r1b6477e  
    4141        src/exception.cpp \
    4242        src/new.cpp \
    43         src/typeinfo.cpp
     43        src/typeinfo.cpp \
     44        src/internal/runtime.cpp
    4445
    4546include $(USPACE_PREFIX)/Makefile.common
  • uspace/lib/cpp/include/typeinfo

    rc2c1966 r1b6477e  
    2727 */
    2828
     29#include <cstdlib>
     30
    2931namespace std
    3032{
  • uspace/lib/cpp/src/typeinfo.cpp

    rc2c1966 r1b6477e  
    2828
    2929#include <cstring>
    30 
    3130#include <typeinfo>
    3231
     
    5049    bool type_info::before(const type_info& other) const noexcept
    5150    {
    52         // TODO: implement (need type_index)
    53         return false;
     51        /**
     52         * cppreference.com:
     53         *  Returns true if the type of this type_info precedes the type
     54         *  of rhs in the implementation's collation order. No guarantees
     55         *  are given; in particular, the collation order can change
     56         *  between the invocations of the same program.
     57         *
     58         * Seems completely arbitrary and the only guarantee
     59         * we have to provide that two comparisons of two same
     60         * type_info instances return the same result.
     61         */
     62        return name() < other.name();
    5463    }
    5564
    5665    size_t type_info::hash_code() const noexcept
    5766    {
    58         // TODO: implement
    59         return size_t{};
     67        /**
     68         * We only need for the hash codes of two type_info
     69         * instances describing the same type to match, nothing
     70         * else.
     71         */
     72        size_t res{};
     73        const char* str = name();
     74        while(*str)
     75            res += static_cast<size_t>(*str++);
     76
     77        return res;
    6078    }
    6179
Note: See TracChangeset for help on using the changeset viewer.