CMake: Simple C++ Reflection

simple c++
simple c++

Reflection is a very useful tool and if you aren’t familiar with the state of affairs in simple C++.

The cmake-reflection-template repository is a small working example of a few source files with added reflection which generates serialization and deserialization routines (using std::any<> for simplicity – so it requires C++17 – but it can be rewritten to serialize to JSON instead).

  • Each CMake target that wants to have reflection should have the target_parse_sources() CMake function called on it like so
  • Each source file in the reflected projects has an attached custom CMake command so when it gets modified that command gets ran
  • That command runs the parser on the file – named for example my_type.h – which generates code and dumps it in a file called my_type.h.inl in a gen folder inside CMAKE_BINARY_DIR
  • The resulting my_type.h.inl can be included either directly in my_type.h or perhaps elsewhere – the forward declarations of the generated functions are written inside the classes in my_type.h using the helper FRIENDS_OF_TYPE(MY_TYPE); macro.

 

It is a bit like what Unreal is doing for reflection of properties – C++ source code is parsed (and annotated with preprocessor identifiers) and each source file includes the generated code for itself.

Read more

CMake 3.16: Support for Precompiled Headers and Unity Builds

cmake
cmake

Modules are coming in C++20 but it will take a while before they are widely adopted, optimized and supported by tooling.

Release of CMake 3.16 does not require resorting to 3rd party CMake scripts from GitHub for precompiled headers and unity builds:

  • To precompile means that the compiler will parse the C++ headers and save its intermediate representation (IR) into a file, and then when compiling the .cpp files of the target that IR will be prepended to them – as if the headers were included – the contents of the PCH are the first thing each translation unit sees

  • Easy to integrate – doesn’t require any C++ code changes
  • ~20-30% speedup with GCC/Clang (can be up to 50%+ with MSVC)
  • For targets with at least 10 .cpp files (takes space & time to compile)

 

What to put in a PCH

  • STL & third-party libs like boost (used in at least ~30% of the sources)
  • Some rarely changing project-specific headers (at least 30% use)
    • for example if you have common utilities for logging/etc.
  • Each time any header which ends up in the PCH is changed – the entire PCH is recompiled along with the entire target which includes it
  • Careful not to put too much into a PCH – once it reaches ~150-200MB you might start hitting diminishing returns
  • How to determine which are the most commonly used header files
    • option 1: do a few searches in the codebase/target
      • <algorithm>, <vector>, <boost/asio.hpp>, etc.
      • note that some header might be included only in a few other header files, but if those headers go everywhere, then the other header gets included almost everywhere as well
    • option 2: – use software to visualize includes & dependencies

Read more

Step By Step Guide to Fix WordPress Stuck in Maintenance Mode

wordpress stuck in maintenance mode
wordpress stuck in maintenance mode

Have you ever been in the position of WordPress stuck in maintenance mode? In fact, you are sure that you have updated and completed correctly. Relax, in this article, you will be guided step by step how to fix errors in WordPress stuck in maintenance mode.

 

What is WordPress Maintenance Mode?

Making any changes to the WordPress website, whether changing plugins, editing core files, or updating, the website will usually experience processes that can trigger errors.

 

That’s what causes the website to be slow, down and even worse it can’t be accessed at all. Of course this can cause a bad user experience for your website visitors. An error website can make visitors disappointed so they choose to leave and no longer visit your website.

 

This maintenance mode can also affect the bounce rate and SEO even when the website goes down for unknown reasons making it difficult for web crawlers to index your website pages in search engines. It’s a loss right?

Read more

MilesWeb’s Best WordPress Hosting Service

MilesWeb WordPress Hosting Service
MilesWeb WordPress Hosting Service

If you plan to create a website on WordPress Cloud, you should consider a WordPress Cloud Hosting based on Cloud platform. WordPress was created primarily as a blogging tool, and it is now one of the most widely used blogging systems.

WordPress is a powerful content management system. WordPress allows you to construct sophisticated websites. Thousands of websites today on the internet are built in WordPress. Also, the users choose the best WordPress hosting services to host them.

If you have a beautiful WordPress site, but that’s not enough. If you have a beautiful WordPress site, but that’s not enough. You need to select a web hosting service provider to make your website accessible and online to all users. It not only creates your web presence but also builds the credibility of your business.

MilesWeb WordPress Hosting Service2
MilesWeb WordPress Hosting Service2

One of the best ways to host your WordPress site is WordPress hosting. WordPress hosting is a hosting platform tailored to meet the needs of WordPress websites.

MilesWeb is a website hosting provider that provides the best managed WordPress hosting service at economical prices. Let us know in brief about their managed WordPress hosting platform.

Read more

How to Enable Debug Mode in WordPress

how to enable debug mode in wordpress
how to enable debug mode in wordpress

Do you know how to enable debug mode in WordPress? Although many people choose the WordPress platform, WordPress users still find problems with their website.

 

If your WordPress website has an error, you can activate the debug mode in WordPress and the error will be recorded in the debug log. You will be able to edit wp-config.php and also view WordPress Error Logs.

 

What is WordPress Debug Mode?

Before you learn how to enable WordPress debug mode, it’s a good idea for you to know what debug mode is.

Debug mode in WordPress will be very useful in solving problems on WordPress websites and will be recorded as an error.log file. That way you can find out the cause of the problem on your WordPress website.

Read more

What Is 502 Bad Gateway and How to Solve It

502 bad gateway
502 bad gateway

Sometimes when you are browsing and opening a website, you experience the 502 Bad Gateway error. One of the most common types of website errors that you will see is the HTTP 502 Bad Gateway Error.

This is a type of error that not only occurs on WordPress websites, but sometimes also occurs on Gmail, Twitter, and Cloudflare.

 

In simple terms, this is a condition where both web managers and web users are faced with a blank condition so that the website can no longer be operated. Likewise, people who want to access the web or blog, will be constrained because the condition of the blog only has the words 502 bad gateway.

 

If you experience 502 bad gateway, don’t panic and despair. This condition is indeed annoying, especially if the website you manage is very influential for the existence of your business.

If you are faced with this problem, there are several steps you can take to solve it. But before stepping on the discussion of how to solve it, it’s a great idea to find out what and the cause. Now for more details, please follow the full discussion below.

Read more

10 Ways to Fix WordPress 403 Forbidden Error

wordpress 403 forbidden
wordpress 403 forbidden

Maybe you are familiar with the term “404 Not Found Error“, but have you ever encountered a WordPress 403 Forbidden Error while accessing a website?

You as a website owner can lose a lot of potential visitors if this error is not fixed immediately. The 403 Forbidden Error message is an HTTP status code that appears when you try to access a page and forbids you to view it.

 

Seeing a 403 Forbidden Error notification on a computer or smartphone screen is definitely annoying and frustrating, here is a guide on how to fix it.

 

What is WordPress 403 Forbidden?

A 403 Forbidden Error is what happens when the web page (or other resource) you are trying to open in a web browser is either disabled or banned. It’s called a 403 Forbidden Error because that’s the HTTP status code that web servers use to describe such errors.

 

You usually encounter this error for one of two reasons. The first is that the owner of the web server has set the access permissions correctly, and you are not allowed to access the resource. The second reason is that the owner of the web server has set the permissions incorrectly and you are denied access when you shouldn’t.

 

You may see a 403 Forbidden Error message that looks different on certain websites. The website may use a slightly different name for this. For example, you might see things like:

  • HTTP Error 403 – Forbidden
  • 403 forbidden request forbidden by administrative rules
  • 403 Forbidden
  • Access Denied You don’t have permission to access
  • Error 403
  • Error 403 Forbidden
  • Error 403 Access Denied
  • HTTP ERROR 403
  • 403 Forbidden – nginx
  • Forbidden
  • You are not authorized to view this page
  • Forbidden: You don’t have permission to access [directory/file] on this server
  • It appears you don’t have permission to access this page
  • HTTP Error 403 – Forbidden – You do not have permission to access the document or program you requested
  • Access to [your domain] was denied. You don’t have the authorization to view this page.

Read more

8 Methods to Fix 401 Unauthorized Error

401 unauthorized
401 unauthorized

It can be said that this 401 Unauthorized error is one of the most annoying WordPress errors. How come? For visitors, you cannot login to the website and enjoy its features.

As for website owners, you cannot enter the admin dashboard from your own website. Annoying, right?

 

You really need to know how to fix WordPress 401 unauthorized or authorization required. You will not realize when it comes and when you experience the error, you will certainly be confused about how to solve it.

This 401 unauthorized error is often found on several types of websites, especially for websites that are already quite large.

If you have a website that is quite large and has a lot of visitor traffic, then don’t be surprised if you experience this.

 

Finding out how to fix an unauthorized 401 WordPress is very important to anticipate if it happens again. If you have learned how to deal with it, it will be easier to act when the website has an error like that. Some error displays may appear as follows:

  • “Authorization Required”
  • “401 Unauthorized”
  • “HTTP Error 401 – Unauthorized”
  • “disabled_client. The OAuth client was disabled”
  • “invalid_client”
  • “deleted_client” etc.

Read more